C#如何关闭指定进程
2024-10-19 11:39:55
public static void KillProcess(string strProcessesByName)//关闭线程
{
foreach (Process p in Process.GetProcesses())//GetProcessesByName(strProcessesByName))
{
if (p.ProcessName.ToUpper().Contains("你要关闭的进程名字"))
{
try
{
p.Kill();
p.WaitForExit(); // possibly with a timeout
}
catch (Win32Exception e)
{
MessageBox.Show(e.Message.ToString()); // process was terminating or can't be terminated - deal with it
}
catch (InvalidOperationException e)
{
MessageBox.Show(e.Message.ToString()); // process has already exited - might be able to let this one go
}
}
}
}
或者这样关闭自己
Environment.Exit();
最新文章
- Android:View随手指移动
- (转)Linux进程间通信
- win7安装 Apache2.2 PHP5.3 MySQL5.6
- 乐在其中设计模式(C#) - 备忘录模式(Memento Pattern)
- [转]Introduction to Core Bluetooth: Building a Heart Rate Monitor
- .net项目架构改造之搭建基于java环境配置一览【上】
- Django REST Framework API Guide 05
- 用vue+element-ui开发后台笔记
- Linux C++ IDEs
- Codeforces Round #486 (Div. 3) D. Points and Powers of Two
- linux服务器时间同步失败解决方法
- [git] commit 相关的操作
- mac下python2.7升级到3.6
- webstorm快捷键汇总
- wpf datagrid 隔行变色
- Windows获取线程起始地址
- 单例Singleton模式的两种实现方法
- Android性能优化来龙去脉总结
- hihoCoder[Offer收割]编程练习赛1题目解析
- Spcomm 属性详解