TimeSpan WaitTimeWithDrift()
 {
     return(Ticks.ToTimeSpan(Math.Max(
                                 Ticks.FromTimeSpan(BackoffTimeoutHelper.defaultInitialWaitTime),
                                 Ticks.Add(Ticks.FromTimeSpan(this.waitTime),
                                           (long)(uint)this.random.Next() % (2 * BackoffTimeoutHelper.maxDriftTicks + 1) - BackoffTimeoutHelper.maxDriftTicks))));
 }
Exemple #2
0
 public void Set(TimeSpan timeFromNow)
 {
     if (timeFromNow != TimeSpan.MaxValue)
     {
         SetAt(Ticks.Add(Ticks.Now, Ticks.FromTimeSpan(timeFromNow)));
     }
 }
Exemple #3
0
 public bool Cancel(IOThreadTimer timer)
 {
     lock (this.ThisLock)
     {
         if (timer.index > 0)
         {
             IOThreadTimer.TimerGroup timerGroup = timer.timerGroup;
             IOThreadTimer.TimerQueue timerQueue = timerGroup.TimerQueue;
             timerQueue.DeleteTimer(timer);
             if (timerQueue.Count > 0)
             {
                 this.UpdateWaitableTimer(timerGroup);
             }
             else
             {
                 IOThreadTimer.TimerGroup otherTimerGroup = this.GetOtherTimerGroup(timerGroup);
                 if (otherTimerGroup.TimerQueue.Count == 0)
                 {
                     long now  = Ticks.Now;
                     long num2 = timerGroup.WaitableTimer.DueTime - now;
                     long num3 = otherTimerGroup.WaitableTimer.DueTime - now;
                     if ((num2 > 0x989680L) && (num3 > 0x989680L))
                     {
                         timerGroup.WaitableTimer.Set(Ticks.Add(now, 0x989680L));
                     }
                 }
             }
             return(true);
         }
         return(false);
     }
 }
Exemple #4
0
            public bool Cancel(IOThreadTimer timer)
            {
                lock (ThisLock)
                {
                    if (timer.index > 0)
                    {
                        TimerGroup timerGroup = timer.timerGroup;
                        TimerQueue timerQueue = timerGroup.TimerQueue;

                        timerQueue.DeleteTimer(timer);

                        if (timerQueue.Count > 0)
                        {
                            UpdateWaitableTimer(timerGroup);
                        }
                        else
                        {
                            TimerGroup otherTimerGroup = GetOtherTimerGroup(timerGroup);
                            if (otherTimerGroup.TimerQueue.Count == 0)
                            {
                                long now = Ticks.Now;
                                long thisGroupRemainingTime  = timerGroup.WaitableTimer.DueTime - now;
                                long otherGroupRemainingTime = otherTimerGroup.WaitableTimer.DueTime - now;
                                if (thisGroupRemainingTime > maxTimeToWaitForMoreTimers &&
                                    otherGroupRemainingTime > maxTimeToWaitForMoreTimers)
                                {
                                    timerGroup.WaitableTimer.Set(Ticks.Add(now, maxTimeToWaitForMoreTimers));
                                }
                            }
                        }

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
Exemple #5
0
            public bool Cancel(IOThreadTimer timer)
            {
                bool flag;

                lock (this.ThisLock)
                {
                    if (timer.index <= 0)
                    {
                        flag = false;
                    }
                    else
                    {
                        IOThreadTimer.TimerGroup timerGroup = timer.timerGroup;
                        IOThreadTimer.TimerQueue timerQueue = timerGroup.TimerQueue;
                        timerQueue.DeleteTimer(timer);
                        if (timerQueue.Count <= 0)
                        {
                            IOThreadTimer.TimerGroup otherTimerGroup = this.GetOtherTimerGroup(timerGroup);
                            if (otherTimerGroup.TimerQueue.Count == 0)
                            {
                                long now     = Ticks.Now;
                                long dueTime = timerGroup.WaitableTimer.DueTime - now;
                                long num     = otherTimerGroup.WaitableTimer.DueTime - now;
                                if (dueTime > (long)0x989680 && num > (long)0x989680)
                                {
                                    timerGroup.WaitableTimer.Set(Ticks.Add(now, (long)0x989680));
                                }
                            }
                        }
                        else
                        {
                            this.UpdateWaitableTimer(timerGroup);
                        }
                        flag = true;
                    }
                }
                return(flag);
            }
Exemple #6
0
 public void Set(int millisecondsFromNow)
 {
     SetAt(Ticks.Add(Ticks.Now, Ticks.FromMilliseconds(millisecondsFromNow)));
 }
Exemple #7
0
 public static TimeSpan Add(TimeSpan timeout1, TimeSpan timeout2)
 {
     return(Ticks.ToTimeSpan(Ticks.Add(Ticks.FromTimeSpan(timeout1), Ticks.FromTimeSpan(timeout2))));
 }
Exemple #8
0
 private TimeSpan WaitTimeWithDrift()
 {
     return(Ticks.ToTimeSpan(Math.Max(Ticks.FromTimeSpan(defaultInitialWaitTime), Ticks.Add(Ticks.FromTimeSpan(this.waitTime), ((long)(((ulong)this.random.Next()) % ((2L * maxDriftTicks) + 1L))) - maxDriftTicks))));
 }