System.Diagnostics.Tests.ProcessWaitingTests.SingleProcess_WaitAfterExited C# (CSharp) Method

SingleProcess_WaitAfterExited() private method

private SingleProcess_WaitAfterExited ( bool addHandlerBeforeStart ) : System.Threading.Tasks.Task
addHandlerBeforeStart bool
return System.Threading.Tasks.Task
        public async Task SingleProcess_WaitAfterExited(bool addHandlerBeforeStart)
        {
            Process p = CreateProcessLong();
            p.EnableRaisingEvents = true;

            var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
            if (addHandlerBeforeStart)
            {
                p.Exited += delegate { tcs.SetResult(true); };
            }
            p.Start();
            if (!addHandlerBeforeStart)
            {
                p.Exited += delegate { tcs.SetResult(true); };
            }

            p.Kill();
            Assert.True(await tcs.Task);

            Assert.True(p.WaitForExit(0));
        }