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

posted on 2012-07-15 22:19  liuxinchen  阅读(300)  评论(0编辑  收藏  举报

导航