public IAsyncResult BeginAdd(Message msg, ulong id, AsyncCallback cb, object state)
            {
                try
                {
                    this.rwLock.EnterWriteLock();
                    this.PurgeExpired();

                    var cmsg = new CachedMessage(msg.SignalKey, msg.Value, msg.Created, id);
                    if (this.messageIndex.Count + 1 < CapacityLimit)
                    {
                        // add and complete
                        this.AddToCache(cmsg);
                        return new CompletedAsyncResult(cb, state);
                    }
                    else
                    {
                        // move the 'Add' operation to pending until we've got room to 
                        // add the item and complete once the item has been dequeued
                        // calling Complete on the AR
                        var addAsyncResult = new AddAsyncResult(cb, state);
                        this.pendingAdds.EnqueueAndDispatch(cmsg, addAsyncResult.Complete);
                        return addAsyncResult;
                    }
                }
                finally
                {
                    this.rwLock.ExitWriteLock();
                }
            }
예제 #2
0
        public IAsyncResult BeginAdd(int number1, int number2, AsyncCallback callback, object state)
        {
            AddAsyncResult asyncResult = new AddAsyncResult(number1, number2, callback, state);

            ThreadPool.QueueUserWorkItem(new WaitCallback(Callback), asyncResult);
            return(asyncResult);
        }
예제 #3
0
        public AddDataContract EndAddDC(IAsyncResult ar)
        {
            AddDataContract result = null;

            try
            {
                if (ar != null)
                {
                    using (AddAsyncResult asyncResult = ar as AddAsyncResult)
                    {
                        if (asyncResult == null)
                        {
                            throw new ArgumentNullException("IAsyncResult parameter is null.");
                        }

                        if (asyncResult.Exception != null)
                        {
                            throw asyncResult.Exception;
                        }

                        asyncResult.AsyncWait.WaitOne();
                        result = asyncResult.AddContract;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorInfo err = new ErrorInfo(ex.Message, "EndAddDC faills");
                throw new FaultException <ErrorInfo>(err, "reason goes here.");
            }
            return(result);
        }
            public IAsyncResult BeginAdd(Message msg, ulong id, AsyncCallback cb, object state)
            {
                try
                {
                    this.rwLock.EnterWriteLock();
                    this.PurgeExpired();

                    var cmsg = new CachedMessage(msg.SignalKey, msg.Value, msg.Created, id);
                    if (this.messageIndex.Count + 1 < CapacityLimit)
                    {
                        // add and complete
                        this.AddToCache(cmsg);
                        return(new CompletedAsyncResult(cb, state));
                    }
                    else
                    {
                        // move the 'Add' operation to pending until we've got room to
                        // add the item and complete once the item has been dequeued
                        // calling Complete on the AR
                        var addAsyncResult = new AddAsyncResult(cb, state);
                        this.pendingAdds.EnqueueAndDispatch(cmsg, addAsyncResult.Complete);
                        return(addAsyncResult);
                    }
                }
                finally
                {
                    this.rwLock.ExitWriteLock();
                }
            }
            static void SendComplete(IAsyncResult result)
            {
                if (!result.CompletedSynchronously)
                {
                    AddAsyncResult addResult         = (AddAsyncResult)result.AsyncState;
                    Exception      completeException = null;

                    try
                    {
                        addResult.CompleteSend(result);
                    }
#pragma warning suppress 56500 // covered by FxCOP
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }

                        completeException = e;
                    }

                    addResult.Complete(false, completeException);
                }
            }
 public void EndAdd(IAsyncResult ar)
 {
     if (ar is CompletedAsyncResult)
     {
         CompletedAsyncResult.End(ar);
     }
     else
     {
         AddAsyncResult.End(ar);
     }
 }
예제 #7
0
        private void Callback(object state)
        {
            AddAsyncResult asyncResult = state as AddAsyncResult;

            try
            {
                asyncResult.Result = InternalAdd(asyncResult.number1, asyncResult.number2);
            }
            finally
            {
                asyncResult.Complete();
            }
        }
예제 #8
0
        private void CallbackDC(object state)
        {
            AddAsyncResult asyncResult = null;

            try
            {
                asyncResult             = state as AddAsyncResult;
                asyncResult.AddContract = InternalAdd(asyncResult.AddContract);
            }
            catch (Exception ex)
            {
                asyncResult.Exception = ex;
            }
            finally
            {
                asyncResult.Complete();
            }
        }
예제 #9
0
        public IAsyncResult BeginAddDC(AddDataContract input, AsyncCallback callback, object state)
        {
            AddAsyncResult asyncResult = null;

            try
            {
                asyncResult = new AddAsyncResult(input, callback, state);

                //Queues a method for execution. The method executes when a thread pool thread becomes available.
                ThreadPool.QueueUserWorkItem(new WaitCallback(CallbackDC), asyncResult);
            }
            catch (Exception ex)
            {
                ErrorInfo err = new ErrorInfo(ex.Message, "BeginAddDC faills");
                throw new FaultException <ErrorInfo>(err, "reason goes here.");
            }

            return(asyncResult);
        }
예제 #10
0
        public int EndAdd(IAsyncResult ar)
        {
            int result = 0;

            if (ar != null)
            {
                using (AddAsyncResult asyncResult = ar as AddAsyncResult)
                {
                    if (asyncResult == null)
                    {
                        throw new ArgumentNullException("IAsyncResult parameter is null.");
                    }

                    asyncResult.AsyncWait.WaitOne();
                    result = asyncResult.Result;
                }
            }
            return(result);
        }
 private void EndCompleteTransfer(IAsyncResult result)
 {
     if (this.reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
     {
         AddAsyncResult.End(result);
     }
     else
     {
         if (this.reliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11)
         {
             throw Fx.AssertAndThrow("Unsupported version.");
         }
         AlreadyCompletedTransferAsyncResult result2 = result as AlreadyCompletedTransferAsyncResult;
         if (result2 != null)
         {
             result2.End();
         }
         else
         {
             this.endSendAckRequestedHandler(result);
         }
     }
 }
 public bool EndAddMessage(IAsyncResult result)
 {
     return(AddAsyncResult.End(result));
 }