Last active
August 31, 2017 23:34
-
-
Save agocke/633949f8220a2975c028fb29036aca3d to your computer and use it in GitHub Desktop.
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
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