private unsafe void Execute() { while (completed == false) { uint bytesRead; uint completionKey; NativeOverlapped *native; bool result = CompletionInterop.GetQueuedCompletionStatus( port, out bytesRead, out completionKey, &native, 1000); if (native != null) { Overlapped overlapped = Overlapped.Unpack(native); CompletionCallback callback = overlapped.AsyncResult as CompletionCallback; if (result) { callback?.Complete((int)bytesRead); } else { callback?.Fail(native); } Overlapped.Free(native); } } }
public void Start() { port = CompletionInterop.CreateIoCompletionPort(new IntPtr(-1), IntPtr.Zero, 0, 0); thread = new Thread(Execute); thread.Start(); }
public void Add(IntPtr handle) { IntPtr result = CompletionInterop.CreateIoCompletionPort(handle, port, (uint)handle.ToInt32(), 0); }