我有以下代码,但为什么ProcessExited从未调用该方法?如果我不使用Windows shell(startInfo.UseShellExecute = false),它也是一样的.
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = path;
startInfo.Arguments = rawDataFileName;
startInfo.WorkingDirectory = Util.GetParentDirectory(path, 1);
try
{
Process correctionProcess = Process.Start(startInfo);
correctionProcess.Exited += new EventHandler(ProcessExited);
correctionProcess.WaitForExit();
status = true;
}
Run Code Online (Sandbox Code Playgroud)
.....
internal void ProcessExited(object sender, System.EventArgs e)
{
//print out here
}
Run Code Online (Sandbox Code Playgroud)
Eli*_*sha 228
要在Exited事件上接收回调,EnableRaisingEvents必须将其设置为true.
Process correctionProcess = Process.Start(startInfo);
correctionProcess.EnableRaisingEvents = true;
correctionProcess.Exited += new EventHandler(ProcessExited);
Run Code Online (Sandbox Code Playgroud)
Ada*_*Cox 16
我遇到的例子那个地方new Process()一个在using条款。如果您想使用该Exited功能,请不要这样做。该using子句将销毁实例以及 上的任何事件句柄Exited。
这个...
using(var process = new Process())
{
// your logic here
}
Run Code Online (Sandbox Code Playgroud)
应该是这个...
var process = new Process();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34551 次 |
| 最近记录: |