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

  • 相关阅读:
    php日常日志写入格式记录
    ssh 配置config 别名
    win10 使用docker
    gulp watch error ENOSPC
    log4net各种Filter使用【转】
    【转】Controllers and Routers in ASP.NET MVC 3
    【转】ASP.NET MVC学习笔记-Controller的ActionResult
    JavaScript 面向对象程序设计(下)——继承与多态 【转】
    Ajax– 刷新页面 【转】
    [webgrid] – selecterow
  • 原文地址:https://www.cnblogs.com/liuxchen/p/2592780.html
Copyright © 2011-2022 走看看