예제 #1
0
        public static void SetupCallback(SocketAsyncEventArgs e)
        {
            ReusableTaskCompletionSource tcs = new ReusableTaskCompletionSource();

            e.UserToken  = tcs;
            e.Completed += CompletionDelegate;
        }
예제 #2
0
        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();
            }
        }