本文介绍了我怎么能知道,如果一个进程正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我得到的引用的System.Diagnostics.Process
,我怎么能知道如果一个进程正在运行?
When I get a reference to a System.Diagnostics.Process
, how can I know if a process is currently running?
推荐答案
这是一种名为做到这一点:
This is a way to do it with the name:
Process[] pname = Process.GetProcessesByName("notepad");
if (pname.Length == 0)
MessageBox.Show("nothing");
else
MessageBox.Show("run");
您可以循环的所有过程中获得的ID为后处理:
You can loop all process to get the ID for later manipulation:
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist){
Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id);
}
这篇关于我怎么能知道,如果一个进程正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!