Add WaitHandle.WaitOneAsync

This commit is contained in:
Oliver Booth 2020-07-15 11:27:28 +01:00
parent 0b8d485514
commit e747921fb7
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
namespace X10D
{
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Extension methods for <see cref="WaitHandle" />.
/// </summary>
public static class WaitHandleExtensions
{
/// <summary>
/// Returns a <see cref="Task" /> which can be awaited until the current <see cref="WaitHandle" /> receives a signal.
/// </summary>
/// <param name="handle">The <see cref="WaitHandle" /> instance.</param>
/// <returns>Returns a task which wraps <see cref="WaitHandle.WaitOne()" />.</returns>
public static Task WaitOneAsync(this WaitHandle handle)
{
return new Task(() => handle.WaitOne());
}
}
}