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

  • 相关阅读:
    C+= concurrent_queue 线程安全测试
    c++ 枚举 在函数中的应用
    shell脚本积累
    hibernate+spring整合增删改事务错误
    checkbox批量删除功能
    html全选和取消全选JS
    hibernate+pageBean实现分页dao层功能代码
    table样式
    WebStorm 11 Lisence server
    Kb,KB,Kbps,Mb,Mbps等一些列概念
  • 原文地址:https://www.cnblogs.com/liuxchen/p/2592780.html
Copyright © 2011-2022 走看看