我正在创建一个负责运行某个程序的进程,我在程序终止时添加了一个事件,但是当我关闭程序时该事件不启动。
这是我的代码,之前创建过程我的程序解压。exe文件并运行。
用事件创建新进程:
Process installerProcess = new Process();
installerProcess.StartInfo.FileName = unpackPath + @"" + unpackFileName;
installerProcess.Exited += InstallerProcess_Exited;
installerProcess.Start();
事件:
private void InstallerProcess_Exited(object sender, EventArgs e)
{
Debug.WriteLine("Process end");
}
您必须在Process
对象上将EnableRaisingEvents
设置为true:
Process installerProcess = new Process();
installerProcess.StartInfo.FileName = unpackPath + @"" + unpackFileName;
installerProcess.EnableRaisingEvents = true;
installerProcess.Exited += InstallerProcess_Exited;
installerProcess.Start();