我怎么知道进程是否正在运行?当我获得对a的引用时System.Diagnostics.Process,如何知道进程当前是否正在运行?
3 回答
慕标琳琳
TA贡献1830条经验 获得超9个赞
同步解决方案:
void DisplayProcessStatus(Process process){
process.Refresh(); // Important
if(process.HasExited)
{
Console.WriteLine("Exited.");
}
else
{
Console.WriteLine("Running.");
} }异步解决方案:
void RegisterProcessExit(Process process){
// NOTE there will be a race condition with the caller here
// how to fix it is left as an exercise
process.Exited += process_Exited;}static void process_Exited(object sender, EventArgs e){
Console.WriteLine("Process has exited.");}- 3 回答
- 0 关注
- 638 浏览
添加回答
举报
0/150
提交
取消
