zoukankan      html  css  js  c++  java
  • Kill 进程的时候需要注意的地方

    private void FrmBackGround_Load(object sender, EventArgs e)
            {
                updateWatcher = new FrmUpdate();

                //进程的名称
                System.Diagnostics.Process[] xx = System.Diagnostics.Process.GetProcessesByName("PicaUI");//程序集名称

                foreach(System.Diagnostics.Process pro in xx)
                {
                    pro.Kill();
                    System.Threading.Thread.Sleep(5000); //关闭进程需要时间,如果没有休眠的话,很容易出问题的
                }

                maxCount = this.GetFilesCount(Application.StartupPath+ @"\DldUpdate");

                string root = Application.StartupPath;

                this.backgroundWorker1.RunWorkerAsync(root);

                updateWatcher.Show();
            }

     foreach(System.Diagnostics.Process pro in xx)
                {
                    pro.Kill();
                    System.Threading.Thread.Sleep(5000); //关闭进程需要时间,如果没有休眠的话,很容易出问题的
                }

    在Kill()  方法调用的时候后面需要有个休眠的时间,因为关掉一个进程的时候需要点时间,如果没有休眠时间,在你需要覆盖或是拷贝文件的时候就会抛出异常,说文件正在使用, 这个休眠时间有的机器慢点的话设置需要更长的时间

  • 相关阅读:
    (22)C#windows打包部署
    (2)OLEDB数据库操作
    (5)C#工具箱-数据
    (21)C#VS快捷键
    (1)OracleClient数据库操作(淘汰)
    (4)C#工具箱-菜单和工具栏
    (3)C#工具箱-容器
    (2)C#工具箱-公共控件2
    (9)oracle 表的基本查询
    企鹅
  • 原文地址:https://www.cnblogs.com/liuxchen/p/2592780.html
Copyright © 2011-2022 走看看