예제 #1
0
        private static async Task StartAndWaitForProcessAsync(CancellationToken token)
        {
            int exitCode;
            DateTime exitTime;

            using (Process process = await Task.Factory.StartNew(() => Process.Start("notepad.exe")))
            using (ProcessExitWatcher watcher = new ProcessExitWatcher(new ProcessExit(process)))
            {
                Console.WriteLine("Waiting for Notepad to exit...");
                await watcher.WaitForExitAsync(token);
                exitCode = watcher.Status.ExitCode;
                exitTime = watcher.Status.ExitTime;
            }

            Console.WriteLine("Done, exited with code {0} at {1}.", exitCode, exitTime);
        }
예제 #2
0
        private static async Task StartAndWaitForProcessAsync(CancellationToken token)
        {
            int      exitCode;
            DateTime exitTime;

            using (Process process = await Task.Factory.StartNew(() => Process.Start("notepad.exe")))
                using (ProcessExitWatcher watcher = new ProcessExitWatcher(new ProcessExit(process)))
                {
                    Console.WriteLine("Waiting for Notepad to exit...");
                    await watcher.WaitForExitAsync(token);

                    exitCode = watcher.Status.ExitCode;
                    exitTime = watcher.Status.ExitTime;
                }

            Console.WriteLine("Done, exited with code {0} at {1}.", exitCode, exitTime);
        }