Skip to content

Instantly share code, notes, and snippets.

@agocke
Last active August 31, 2017 23:34
Show Gist options
  • Save agocke/633949f8220a2975c028fb29036aca3d to your computer and use it in GitHub Desktop.
Save agocke/633949f8220a2975c028fb29036aca3d to your computer and use it in GitHub Desktop.
class C
{
[DllImport...]
private static extern IntPtr GetAHandle();
private static Task WrapHandle()
{
var handle = GetAHandle();
var tcs = new TaskCompletionSource();
Task.Run(() =>
{
var e = new ManualResetEventSlim();
using (var safeHandle = new SafeWaitHandle(handle, true))
{
e.SafeWaitHandle =
e.Wait();
}
tcs.TrySetResult(true);
});
return tcs.Task;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment