Пример #1
0
        public void Accept(Action <ISocket> callback, Action <Exception> error)
        {
            //try
            //{
            //    SocketWrapper result = new SocketWrapper(_socket.Accept());

            //    callback(result);
            //}
            //catch (Exception e)
            //{
            //    error(e);
            //}
            AsyncSocketAcceptState state = new AsyncSocketAcceptState()
            {
                Callback = callback,
                Error    = error
            };

            ThreadPool.QueueUserWorkItem(new WaitCallback(InnerAccept), state);
        }
Пример #2
0
        private void InnerAccept(object state)
        {
            AsyncSocketAcceptState stateValue = state as AsyncSocketAcceptState;

            try
            {
                if (stateValue == null)
                {
                    return;
                }

                SocketWrapper result = new SocketWrapper(_socket.Accept());

                stateValue.Callback(result);
            }
            catch (Exception e)
            {
                stateValue.Error(e);
            }
        }