Disable raising events

pull/643/head
NextTurn 2020-08-10 00:00:00 +08:00 committed by Next Turn
parent b85593eb11
commit e97bc5bc72
1 changed files with 11 additions and 1 deletions

View File

@ -532,6 +532,9 @@ namespace WinSW
} }
} }
/// <summary>
/// <paramref name="onExited"/> will not be raised if <see cref="Process.EnableRaisingEvents"/> is <see langword="false"/>.
/// </summary>
private Process StartProcess(string executable, string? arguments, LogHandler? logHandler = null, Action<Process>? onExited = null) private Process StartProcess(string executable, string? arguments, LogHandler? logHandler = null, Action<Process>? onExited = null)
{ {
var startInfo = new ProcessStartInfo(executable, arguments) var startInfo = new ProcessStartInfo(executable, arguments)
@ -588,9 +591,16 @@ namespace WinSW
{ {
process.Exited += (sender, _) => process.Exited += (sender, _) =>
{ {
Process process = (Process)sender!;
if (!process.EnableRaisingEvents)
{
return;
}
try try
{ {
onExited((Process)sender!); onExited(process);
} }
catch (Exception e) catch (Exception e)
{ {