示例#1
0
                static bool OpenComplete(IAsyncResult openResult)
                {
                    OperationAsyncResult thisPtr = (OperationAsyncResult)openResult.AsyncState;

                    try
                    {
                        ((ICommunicationObject)thisPtr.parent).EndOpen(openResult);
                    }
                    finally
                    {
                        Queue <OperationAsyncResult> localWaiters = null;

                        lock (thisPtr.parent.thisLock)
                        {
                            localWaiters                 = thisPtr.parent.waiters;
                            thisPtr.parent.waiters       = null;
                            thisPtr.parent.openCompleted = true;
                        }

                        if (localWaiters != null && localWaiters.Count > 0)
                        {
                            if (signalWaiter == null)
                            {
                                signalWaiter = new Action <object>(SignalWaiter);
                            }

                            //foreach over Queue<T> goes FIFO
                            foreach (OperationAsyncResult waiter in localWaiters)
                            {
                                ActionItem.Schedule(signalWaiter, waiter);
                            }
                        }
                    }
                    return(thisPtr.CallOperation());
                }
示例#2
0
                static void SignalWaiter(object state)
                {
                    OperationAsyncResult waiter = (OperationAsyncResult)state;

                    try
                    {
                        if (waiter.CallOperation())
                        {
                            waiter.Complete(false);
                        }
                    }
                    catch (Exception exception)
                    {
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        waiter.Complete(false, exception);
                    }
                }