private static void Callback(IAsyncResult result)
 {
     if (result.CompletedSynchronously)
     {
         return;
     }
     Microsoft.ServiceBus.Channels.CloseCollectionAsyncResult.CallbackState asyncState = (Microsoft.ServiceBus.Channels.CloseCollectionAsyncResult.CallbackState)result.AsyncState;
     asyncState.Result.CompleteClose(asyncState.Instance, result);
 }
        public CloseCollectionAsyncResult(TimeSpan timeout, AsyncCallback otherCallback, object state, IList <ICommunicationObject> collection) : base(otherCallback, state)
        {
            IAsyncResult asyncResult;

            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            this.count = collection.Count;
            if (this.count == 0)
            {
                base.Complete(true);
                return;
            }
            foreach (ICommunicationObject communicationObject in collection)
            {
                if (communicationObject != null)
                {
                    Microsoft.ServiceBus.Channels.CloseCollectionAsyncResult.CallbackState callbackState = new Microsoft.ServiceBus.Channels.CloseCollectionAsyncResult.CallbackState(this, communicationObject);
                    try
                    {
                        asyncResult = communicationObject.BeginClose(timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.CloseCollectionAsyncResult.nestedCallback, callbackState);
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        this.Decrement(true, exception);
                        communicationObject.Abort();
                        continue;
                    }
                    if (!asyncResult.CompletedSynchronously)
                    {
                        continue;
                    }
                    this.CompleteClose(communicationObject, asyncResult);
                }
                else
                {
                    this.Decrement(true);
                }
            }
        }