Ejemplo n.º 1
0
        internal Message ReceiveInternal(MessageCallback callback, int timeout = 60000)
        {
            this.ThrowIfDetaching("Receive");
            if (this.totalCredit < 0)
            {
                this.SetCredit(DefaultCredit, true);
            }

            Waiter waiter = null;

            lock (this.ThisLock)
            {
                MessageNode first = (MessageNode)this.receivedMessages.First;
                if (first != null)
                {
                    this.receivedMessages.Remove(first);
                    this.OnDeliverMessage();
                    return(first.Message);
                }

                if (timeout == 0)
                {
                    return(null);
                }

#if DOTNET || NETFX_CORE
                waiter = callback == null ? (Waiter) new SyncWaiter() : new AsyncWaiter(this, callback);
#else
                waiter = new SyncWaiter();
#endif
                this.waiterList.Add(waiter);
            }

            return(waiter.Wait(timeout));
        }
Ejemplo n.º 2
0
        internal Message ReceiveInternal(MessageCallback callback, int timeout = 60000)
        {
            Waiter waiter = null;

            lock (this.ThisLock)
            {
                this.ThrowIfDetaching("Receive");
                MessageNode first = (MessageNode)this.receivedMessages.First;
                if (first != null)
                {
                    this.receivedMessages.Remove(first);
                    this.OnDeliverMessage();
                    return(first.Message);
                }

                if (timeout > 0)
                {
#if NETFX || NETFX40 || DOTNET || NETFX_CORE || WINDOWS_STORE || WINDOWS_PHONE
                    waiter = callback == null ? (Waiter) new SyncWaiter() : new AsyncWaiter(this, callback);
#else
                    waiter = new SyncWaiter();
#endif
                    this.waiterList.Add(waiter);
                }
            }

            // send credit after waiter creation to avoid race condition
            if (this.totalCredit < 0)
            {
                this.SetCredit(DefaultCredit, true);
            }

            return(timeout > 0 ? waiter.Wait(timeout) : null);
        }
Ejemplo n.º 3
0
        internal Message ReceiveInternal(MessageCallback callback, int timeout = 60000)
        {
            Waiter waiter = null;
            lock (this.ThisLock)
            {
                this.ThrowIfDetaching("Receive");
                MessageNode first = (MessageNode)this.receivedMessages.First;
                if (first != null)
                {
                    this.receivedMessages.Remove(first);
                    this.OnDeliverMessage();
                    return first.Message;
                }

                if (timeout > 0)
                {
#if NETFX || NETFX40 || DOTNET || NETFX_CORE || WINDOWS_STORE || WINDOWS_PHONE
                    waiter = callback == null ? (Waiter)new SyncWaiter() : new AsyncWaiter(this, callback);
#else
                    waiter = new SyncWaiter();
#endif
                    this.waiterList.Add(waiter);
                }
            }

            // send credit after waiter creation to avoid race condition
            if (this.totalCredit < 0)
            {
                this.SetCredit(DefaultCredit, true);
            }

            return timeout > 0 ? waiter.Wait(timeout) : null;
        }
Ejemplo n.º 4
0
        internal Message ReceiveInternal(MessageCallback callback, int timeout = 60000)
        {
            this.ThrowIfDetaching("Receive");
            if (this.totalCredit < 0)
            {
                this.SetCredit(DefaultCredit, true);
            }

            Waiter waiter = null;
            lock (this.ThisLock)
            {
                MessageNode first = (MessageNode)this.receivedMessages.First;
                if (first != null)
                {
                    this.receivedMessages.Remove(first);
                    this.OnDeliverMessage();
                    return first.Message;
                }

                if (timeout == 0)
                {
                    return null;
                }

            #if DOTNET || NETFX_CORE
                waiter = callback == null ? (Waiter)new SyncWaiter() : new AsyncWaiter(this, callback);
            #else
                waiter = new SyncWaiter();
            #endif
                this.waiterList.Add(waiter);
            }

            return waiter.Wait(timeout);
        }