代码如下: static void StartProcess(string folder, string processName){string path = Path.Combine(folder, processName);try{Process.Start(path);}catch (Exception ex){Console.WriteLine(string.For...
代码如下:
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#如何杀进程和启动进程
基础教程推荐
猜你喜欢
- C# WPF开源UI控件库MaterialDesign介绍 2023-05-16
- C# EF Core可视化工具的使用及EF Core入门语句操作代码 2023-05-22
- C#利用SFTP实现上传下载 2022-11-19
- C#设计模式之建造者模式生成器模式示例详解 2023-06-28
- Linux+Nginx+Supervisor部署ASP.NET Core实操手册 2023-09-28
- unity 如何使用文件流读取streamingassets下的资源 2023-04-14
- .net core 部署 centos 7.6 2023-09-27
- C#中静态方法和实例化方法的区别、使用 2023-02-25
- c#项目实现发布到服务器全过程 2023-07-18
- C#的十种语法糖介绍 2023-05-22