我怎么知道進(jìn)程是否正在運(yùn)行?當(dāng)我獲得對(duì)a的引用時(shí)System.Diagnostics.Process,如何知道進(jìn)程當(dāng)前是否正在運(yùn)行?
3 回答

慕標(biāo)琳琳
TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超9個(gè)贊
同步解決方案:
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 關(guān)注
- 633 瀏覽
添加回答
舉報(bào)
0/150
提交
取消