mirror of
https://github.com/ckaczor/Common.git
synced 2026-01-14 01:25:43 -05:00
Add async task for starting a process
This commit is contained in:
33
IO/ProcessAsync.cs
Normal file
33
IO/ProcessAsync.cs
Normal file
@@ -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<bool>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user