-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect current Hyper-V state; async operations; F1 info message
- Loading branch information
Showing
5 changed files
with
140 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace HyperVSwitch | ||
{ | ||
internal static class Extensions | ||
{ | ||
/// <summary> | ||
/// Waits asynchronously for the process to exit. | ||
/// </summary> | ||
/// <param name="process">The process to wait for cancellation.</param> | ||
/// <param name="cancellationToken">A cancellation token. If invoked, the task will return | ||
/// immediately as canceled.</param> | ||
/// <returns>A Task representing waiting for the process to end.</returns> | ||
public static Task WaitForExitAsync(this Process process, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
var tcs = new TaskCompletionSource<object>(); | ||
process.EnableRaisingEvents = true; | ||
process.Exited += (sender, args) => tcs.TrySetResult(null); | ||
if (cancellationToken != default(CancellationToken)) | ||
{ | ||
cancellationToken.Register(tcs.SetCanceled); | ||
} | ||
return tcs.Task; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters