From 5c78e979ff37282baceaea6faa8dd089c7a16ee9 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Tue, 4 Nov 2014 19:24:52 -0500 Subject: [PATCH] Add async task for starting a process --- Common.csproj | 1 + IO/ProcessAsync.cs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 IO/ProcessAsync.cs diff --git a/Common.csproj b/Common.csproj index 5ea00e1..d693b1e 100644 --- a/Common.csproj +++ b/Common.csproj @@ -145,6 +145,7 @@ + diff --git a/IO/ProcessAsync.cs b/IO/ProcessAsync.cs new file mode 100644 index 0000000..583aa0c --- /dev/null +++ b/IO/ProcessAsync.cs @@ -0,0 +1,33 @@ +using System.Diagnostics; +using System.Threading.Tasks; + +namespace Common.IO +{ + public class ProcessAsync + { + public static Task RunProcessAsync(string fileName, string arguments) + { + var taskCompletionSource = new TaskCompletionSource(); + + var process = new Process + { + StartInfo = + { + FileName = fileName, + Arguments = arguments + }, + EnableRaisingEvents = true + }; + + process.Exited += (sender, args) => + { + taskCompletionSource.SetResult(true); + process.Dispose(); + }; + + process.Start(); + + return taskCompletionSource.Task; + } + } +}