我只想問如何「終止」正在運行的應用程序/處理您的意見/建議之外的另一個過程是C#C#/。NET:關閉主窗口
現在,我有以下代碼:
Process myProcess;
private void btnOpen_Click(object sender, RoutedEventArgs e)
{
DirectoryInfo di = new DirectoryInfo(System.Environment.GetFolderPath(Environment.SpecialFolder.Programs));
myProcess = Process.Start(di + @"\Wosk\Wosk.appref-ms"); // opening a file coming for Startup Menu
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
myProcess.Kill(); // not working - Cannot process request because the process has exited
}
我也試過myProcess.Close();但沒有發生。
這是錯誤的方法,因爲在返回false之後立即可以退出該進程。所以檢查'if(!myProcess.HasExited){myProcess.Kill(); }'仍然可以拋出異常。只需調用'Kill'並處理產生的異常就好多了。 – JaredPar 2010-03-29 15:56:26