internal void AfterReply(ref MessageRpc rpc)
        {
            if (rpc.Operation.IsTerminating && rpc.Channel.HasSession)
            {
                IOThreadTimer timer = new IOThreadTimer(new Action<object>(TerminatingOperationBehavior.AbortChannel),
                                                        rpc.Channel.Binder.Channel, false);

                timer.Set(rpc.Channel.CloseTimeout);
            }
        }
 private bool AddTimer(IPeerNeighbor neighbor)
 {
     bool flag = false;
     lock (this.ThisLock)
     {
         if ((this.state == State.Opened) && (neighbor.State == PeerNeighborState.Connecting))
         {
             IOThreadTimer timer = new IOThreadTimer(new Action<object>(this.OnConnectTimeout), neighbor, true);
             timer.Set(this.config.ConnectTimeout);
             this.timerTable.Add(neighbor, timer);
             flag = true;
         }
     }
     return flag;
 }
 private List<InstancePersistenceEvent> StartWaiting(WaitForEventsAsyncResult result, IOThreadTimer timeoutTimer, TimeSpan timeout)
 {
     lock (this.ThisLock)
     {
         if (this.waitResult != null)
         {
             throw Fx.Exception.AsError(new InvalidOperationException(SRCore.WaitAlreadyInProgress));
         }
         if (!this.IsValid)
         {
             throw Fx.Exception.AsError(new OperationCanceledException(SRCore.HandleFreed));
         }
         if ((this.boundOwnerEvents != null) && (this.boundOwnerEvents.Count > 0))
         {
             List<InstancePersistenceEvent> list = this.Store.SelectSignaledEvents(this.boundOwnerEvents, this.Owner);
             if (list != null)
             {
                 return list;
             }
         }
         this.waitResult = result;
         if (timeoutTimer != null)
         {
             timeoutTimer.Set(timeout);
         }
         return null;
     }
 }
Пример #4
0
        void WriteStreamedMessage(TimeSpan timeout)
        {
            this.outputStream = GetWrappedOutputStream();

            // Since HTTP streams don't support timeouts, we can't just use TimeoutStream here. 
            // Rather, we need to run a timer to bound the overall operation
            if (onStreamSendTimeout == null)
            {
                onStreamSendTimeout = new Action<object>(OnStreamSendTimeout);
            }
            IOThreadTimer sendTimer = new IOThreadTimer(onStreamSendTimeout, this, true);
            sendTimer.Set(timeout);

            try
            {
                MtomMessageEncoder mtomMessageEncoder = messageEncoder as MtomMessageEncoder;
                if (mtomMessageEncoder == null)
                {
                    messageEncoder.WriteMessage(this.message, this.outputStream);
                }
                else
                {
                    mtomMessageEncoder.WriteMessage(this.message, this.outputStream, this.mtomBoundary);
                }
            }
            finally
            {
                sendTimer.Cancel();
            }
        }
            void SetTimer(IOThreadTimer timer, TimeSpan ts)
            {
                Fx.Assert(timer != null && ts >= TimeSpan.Zero, String.Empty);

                // It is ok to dirty read the state, the consistency will be ensured by persis/unload itself.
                if (this.instance.state == State.Suspended)
                {
                    // Unload/Persist immediately when suspended 
                    timer.Set(TimeSpan.Zero);
                }
                else
                {
                    timer.Set(ts);
                }
            }
        bool EnqueueRetry()
        {
            bool result = false;

            int delay = this.GetRetryDelay();

            if (this.timeoutHelper.RemainingTime().TotalMilliseconds > delay)
            {
                this.sqlCommand.Dispose();
                IOThreadTimer iott = new IOThreadTimer(StartCommandCallback, new SqlCommandAsyncResult(CloneSqlCommand(this.sqlCommand), this.connectionString, this.eventTraceActivity, this.dependentTransaction,
                    this.timeoutHelper.RemainingTime(), this.retryCount, this.maximumRetries, this.PrepareAsyncCompletion(onRetryCommandCallback), this), false);
                iott.Set(delay);

                if (TD.QueuingSqlRetryIsEnabled())
                {
                    TD.QueuingSqlRetry(this.eventTraceActivity, delay.ToString(CultureInfo.InvariantCulture));
                }

                result = true;
            }

            return result;
        }
Пример #7
0
        // Add a timer for the specified neighbor to the timer table. The timer is only added
        // if Connector is open and the neighbor is in Connecting state.
        bool AddTimer(IPeerNeighbor neighbor)
        {
            bool added = false;

            lock (ThisLock)
            {
                if (state == State.Opened && neighbor.State == PeerNeighborState.Connecting)
                {
                    IOThreadTimer timer = new IOThreadTimer(new Action<object>(OnConnectTimeout), neighbor, true);
                    timer.Set(this.config.ConnectTimeout);
                    this.timerTable.Add(neighbor, timer);
                    added = true;
                }
            }

            return added;
        }
        public virtual void Open()
        {
            ThrowIfOpened("Open");
            if (this.refreshInterval <= TimeSpan.Zero)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("RefreshInterval", SR.GetString(SR.RefreshIntervalMustBeGreaterThanZero, this.refreshInterval));
            if (this.CleanupInterval <= TimeSpan.Zero)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("CleanupInterval", SR.GetString(SR.CleanupIntervalMustBeGreaterThanZero, this.cleanupInterval));

            //check that we are good to open
            timer = new IOThreadTimer(new Action<object>(CleanupActivity), null, false);
            timer.Set(CleanupInterval);
            opened = true;
        }
 private void WriteStreamedMessage(TimeSpan timeout)
 {
     this.outputStream = this.supportsConcurrentIO ? ((Stream) new BufferedOutputAsyncStream(this.outputStream, 0x4000, 4)) : ((Stream) new BufferedStream(this.outputStream, 0x8000));
     if (onStreamSendTimeout == null)
     {
         onStreamSendTimeout = new Action<object>(HttpOutput.OnStreamSendTimeout);
     }
     IOThreadTimer timer = new IOThreadTimer(onStreamSendTimeout, this, true);
     timer.Set(timeout);
     try
     {
         MtomMessageEncoder messageEncoder = this.messageEncoder as MtomMessageEncoder;
         if (messageEncoder == null)
         {
             this.messageEncoder.WriteMessage(this.message, this.outputStream);
         }
         else
         {
             messageEncoder.WriteMessage(this.message, this.outputStream, this.mtomBoundary);
         }
     }
     finally
     {
         timer.Cancel();
     }
 }