Beispiel #1
0
        /// <summary>
        /// 异步接收数据
        /// </summary>
        /// <param name="callback">回调函数</param>
        /// <param name="state">参数</param>
        public void AsyncReceive(ReceiveDataCallback callback, object state)
        {
            AsyncReceiveData state2 = new AsyncReceiveData
            {
                Client   = this.m_client,
                Callback = callback,
                State    = state
            };

            ThreadPool.QueueUserWorkItem(this.AsyncReceive, state2);
        }
Beispiel #2
0
        /// <summary>
        /// 异步接收数据
        /// </summary>
        /// <param name="state">参数</param>
        private void AsyncReceive(object state)
        {
            AsyncReceiveData asyncReceiveData = (AsyncReceiveData)state;

            if (asyncReceiveData != null)
            {
                while (asyncReceiveData.Client.Connected)
                {
                    byte[] array = this.Receive(asyncReceiveData.Client);
                    if (array != null)
                    {
                        asyncReceiveData.Callback?.Invoke(array, asyncReceiveData.State);
                        goto IL_83;
                    }
                }
                this.OnConnectionDisconnected(asyncReceiveData.Client);
            }
            IL_83 :;
        }