Catch occasional InvalidOperationException in Session lifetimeTask

This commit is contained in:
Jordan Brown
2018-08-07 20:17:46 -04:00
parent 62054c0499
commit 00dd5d29f2
@@ -57,8 +57,16 @@ namespace Tgstation.Server.Host.Components.Watchdog
return result;
}, default, TaskCreationOptions.LongRunning, TaskScheduler.Current);
lifetimeTask = new TaskCompletionSource<int>();
process.EnableRaisingEvents = true;
process.Exited += (a, b) => lifetimeTask.SetResult(process.ExitCode);
try
{
process.EnableRaisingEvents = true;
process.Exited += (a, b) => lifetimeTask.TrySetResult(process.ExitCode);
}
catch (InvalidOperationException)
{
//dead proccess
lifetimeTask.TrySetResult(process.ExitCode);
}
}
/// <inheritdoc />