0
在我的C#Widows窗體上,即使在退出後我也想使用Process對象信息,但我得到異常「系統進程已退出,因此請求信息不可用「。保存處理對象信息以便在其退出後使用
我到目前爲止所嘗試的是將它保存爲一個var,並用我的ListView項標記它,但它仍會拋出相同的異常。
//ListView Parameters (omitted redundant ones)
Process currentProcess = Process.GetProcessById(Convert.ToInt32(processStringID);
newListViewItem.Tag = currentProcess;
listView.Items.Add(newListViewItem);
我有選擇的指數的情況下更改,因此當用戶點擊的ListView項目,它應該顯示有關已標記,即使它已經退出該項目的過程信息。
private void listView_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
Process processItem = (Process)listView.SelectedItems[0].Tag;
//Sample of getting process information (Error happens here)
MessageBox.Show(processItem.Name + processItem.VersionInfo);
}
catch (Exception ex)
{
throw ex;
}
}
Tldr;我需要一種方法來保存整個Process對象,以便即使流程已經退出,我也可以獲取它的信息。對於如何實現這一點我很樂意。請協助我,因爲我目前對編程的理解無法解決任何問題。
會議?爲了澄清,我的程序是一個C#Windows窗體程序,而不是一個Web應用程序。對不起,如果我以前沒有讓自己清楚。 – Wally