public static void SetupCallback(SocketAsyncEventArgs e) { ReusableTaskCompletionSource tcs = new ReusableTaskCompletionSource(); e.UserToken = tcs; e.Completed += CompletionDelegate; }
private static void CompletionCallback(object sender, SocketAsyncEventArgs e) { ReusableTaskCompletionSource tcs = (ReusableTaskCompletionSource)e.UserToken; if (e.SocketError != SocketError.Success) { tcs.SetException(new SocketException((int)e.SocketError)); } else { tcs.SetResult(); } }