public static TaskAwaiter<int> GetAwaiter(this Process process) { var tcs = new TaskCompletionSource<int>(); process.EnableRaisingEvents = true; process.Exited += (s, e) => tcs.TrySetResult(process.ExitCode); if (process.HasExited) tcs.TrySetResult(process.ExitCode); return tcs.Task.GetAwaiter(); }