Ejemplo n.º 1
0
        public SocketBaseResponse <T> EndSend(ref string resultStr, IAsyncResult ar)
        {
            SocketAsyncResult <T> result = ar as SocketAsyncResult <T>;

            if (Interlocked.CompareExchange(ref result.EndCallCount, 1, 0) == 1)
            {
                throw new Exception("End方法只能调用一次。");
            }
            result.AsyncWaitHandle.WaitOne();
            resultStr = result.ResultStr;
            return(result.FinnalyResult);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        private void AsyncRequest(object obj)
        {
            SocketAsyncResult <T> asyncResult = obj as SocketAsyncResult <T>;

            if (_socketClient.SendRequest(_request))
            {
                asyncResult.ResultStr = _socketClient.Listen();
            }
            asyncResult.FinnalyResult = SerializeHelper.JsonDeserialize <SocketBaseResponse <T> >(asyncResult.ResultStr);

            // 是否同步完成
            asyncResult._completedSynchronously = false;
            asyncResult._isCompleted            = true;
            ((ManualResetEvent)asyncResult.AsyncWaitHandle).Set();
            if (asyncResult._userCallback != null)
            {
                asyncResult._userCallback(asyncResult);
            }
        }
Ejemplo n.º 3
0
        public IAsyncResult BeginSend(SocketBaseRequest request, SocketClient socketClient, AsyncCallback userCallback, object asyncState)
        {
            SocketAsyncResult <T> result = new SocketAsyncResult <T>(request, socketClient, userCallback, asyncState);

            return(result);
        }