mirror of
https://github.com/ckaczor/Common.git
synced 2026-01-13 17:22:40 -05:00
Add async task for starting a process
This commit is contained in:
@@ -145,6 +145,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DateTimeExtensions.cs" />
|
||||
<Compile Include="IO\ProcessAsync.cs" />
|
||||
<Compile Include="Security.cs" />
|
||||
<Compile Include="Trace\BeginEndTracer.cs" />
|
||||
<Compile Include="Extensions\Extensions.cs" />
|
||||
|
||||
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