【发布时间】:2016-08-05 04:23:06
【问题描述】:
在我的 C# Widows 表单上,我想在进程对象退出后使用它的信息,但我收到异常 “系统进程已退出,因此请求的信息不可用” 。
到目前为止,我尝试将其保存为 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# listview c#-4.0 process