c#如何杀进程和启动进程

代码如下:

        static void StartProcess(string folder, string processName)
        {
            string path = Path.Combine(folder, processName);
            try
            {
                Process.Start(path);
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Error:{0}\n{1}", ex.Message, ex.StackTrace));
            }
        }


        static void KillProcess(string processName)
        {
            if (string.IsNullOrEmpty(processName))
                return;
            processName = Path.GetFileNameWithoutExtension(processName).ToLower();
            foreach (Process p in Process.GetProcesses())
            {
                if (p.ProcessName.ToLower() != processName)
                    continue;

                try
                {
                    p.Kill();
                    p.WaitForExit();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(string.Format("Error:{0}\n{1}", ex.Message, ex.StackTrace));
                }
            }
        }

 

转载请注明出处:https://www.cnblogs.com/jietian331/p/14376769.html

 

c#如何杀进程和启动进程

上一篇:wpf中将引用的dll文件打包到exe中


下一篇:c# DataTable使用