码迷,mamicode.com
首页 > Windows程序 > 详细

winform打开进程与关闭进程

时间:2015-07-16 00:23:32      阅读:427      评论:0      收藏:0      [点我收藏+]

标签:

#region 判断某进程名是否运行
        /// <summary>
        /// 关闭指定名称的进程
        /// </summary>
        /// <param name="processname"></param>
        void KillProcess(string processname)
        {
            Process[] allProcess = Process.GetProcesses();
            foreach (Process p in allProcess)
            {
                if (p.ProcessName.ToLower() + ".exe" ==processname.ToLower())
                {
                    for (int i = 0; i < p.Threads.Count; i++)
                        p.Threads[i].Dispose();
                    p.Kill();
                   
                    break;
                }
            }
        
        }
        /// <summary>
        /// 运行应用程序目录下的进程
        /// </summary>
        /// <param name="precessname">进程名称</param>
        void RunProcess(string processname)
        {
            Process[] allProcess = Process.GetProcesses();
            bool isRun = false;
            foreach (Process p in allProcess)
            {
                if (p.ProcessName.ToLower() + ".exe" == processname.ToLower())
                {
                    isRun = true;
                    break;
                }
            }
            if (isRun == false)
            {
                if(File.Exists(Application.StartupPath + "\\" + processname))
                Process.Start(Application.StartupPath + "\\" + processname);
            }
        }
        #endregion

 

winform打开进程与关闭进程

标签:

原文地址:http://www.cnblogs.com/zfanlong1314/p/4649703.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!