我怎么知道進程是否正在運行?當我獲得對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 關注
- 629 瀏覽
添加回答
舉報
0/150
提交
取消