Process cExe = new Process();
cExe .StartInfo.FileName = "cexe.exe";
cExe .EnableRaisingEvents = true;
cExe .Exited += this.cExited;
Run Code Online (Sandbox Code Playgroud)
这是退出的方法
private void cExited(object o, EventArgs e)
{
MessageBox.Show(/* SHOW FILE NAME HERE */);
}
Run Code Online (Sandbox Code Playgroud)
如何从退出的方法中获取有关该过程的信息?哪个变量(o,e)给我这个数据以及它们的含义是什么类型?
使用时.Net Base Class Library,您会发现每个事件都传递两个参数.
首先是类型System.Object,其他类型(或后代)System.EventArgs.
第一个参数object sender可以安全地转换为引发该事件的类的类型.在您的情况下是类型System.Diagnostics.Process.
private void cExited(object o, EventArgs e)
{
Process p = (Process)o;
// Use p here
}
Run Code Online (Sandbox Code Playgroud)