Пример #1
0
        public bool ScheduleReceive(Action <bool> whenDone)
        {
            CoreEventSource.ReceiveStart(name, IsAlive);

            if (!IsAlive)
            {
                whenDone(false);
                return(false);
            }

            if (Interlocked.CompareExchange(ref isReceiving, 1, 0) != 0)
            {
                return(false);
            }

            recvArgs.UserToken = whenDone;

            if (!socket.ReceiveAsync(recvArgs))
            {
                // receive was done synchronously
                ReceiveAsyncCompleted(null, recvArgs);
            }

            return(true);
        }
Пример #2
0
        public void ScheduleReceive(Action <bool> whenDone)
        {
            if (trace.IsEnabled())
            {
                trace.ReceiveStart(name, IsAlive);
            }

            if (!IsAlive)
            {
                whenDone(false);
                return;
            }

            IsBusy             = true;
            recvArgs.UserToken = whenDone;

            if (!socket.ReceiveAsync(recvArgs))
            {
                // receive was done synchronously
                ReceiveAsyncCompleted(null, recvArgs);
            }
        }