2011-07-17 38 views

回答

8

.NET Framework內置了對此的支持。您需要使用Process.Start method來啓動該進程,然後調用WaitForExit method,這會阻止應用程序的執行,直到您啓動的進程完成並關閉。

示例代碼:

// Start the process. 
Process proc = Process.Start("notepad.exe"); // TODO: NEVER hard-code strings!!! 

// Wait for the process to end. 
proc.WaitForExit(); 

// Show your message box. 
MessageBox.Show("Process finished."); 


相關知識庫文章:How to wait for a shelled application to finish using Visual C#

+0

人們永遠不會誇大事件處理程序的優點 - 而OnExited是一個不錯的選擇。 – Olipro

11

創建/附加到該進程,然後要麼使用WaitForExit()阻塞,直到它已退出,或者如果使用OnExited事件您不希望應用程序在等待應用程序退出時阻止。

我衷心建議您閱讀文檔Process - right here

1

我想這是你想要做什麼:

System.Diagnostics.Process process=new System.Diagnostics.Process(); 
process.StartInfo.FileName = "process.exe"; 
process.Start(); 
process.WaitForExit(); 
//process ended 
MessageBox.Show("Process terminated");