internal override TimerThread.Timer CreateTimer(TimerThread.Callback callback, object context) { TimerThread.TimerNode node = new TimerThread.TimerNode(callback, context, base.Duration, this.m_Timers); bool flag = false; lock (this.m_Timers) { if (this.m_Timers.Next == this.m_Timers) { flag = true; } node.Next = this.m_Timers; node.Prev = this.m_Timers.Prev; this.m_Timers.Prev.Next = node; this.m_Timers.Prev = node; } if (flag) { TimerThread.Prod(); } return node; }
internal bool Fire() { if (this.m_TimerState == TimerState.Ready) { int tickCount = Environment.TickCount; if (TimerThread.IsTickBetween(base.StartTime, base.Expiration, tickCount)) { return false; } bool flag = false; lock (this.m_QueueLock) { if (this.m_TimerState == TimerState.Ready) { this.m_TimerState = TimerState.Fired; this.Next.Prev = this.Prev; this.Prev.Next = this.Next; this.Next = null; this.Prev = null; flag = this.m_Callback != null; } } if (flag) { try { TimerThread.Callback callback = this.m_Callback; object context = this.m_Context; this.m_Callback = null; this.m_Context = null; callback(this, tickCount, context); } catch (Exception exception) { if (NclUtilities.IsFatal(exception)) { throw; } if (Logging.On) { Logging.PrintError(Logging.Web, string.Concat(new object[] { "TimerThreadTimer#", base.StartTime.ToString(NumberFormatInfo.InvariantInfo), "::Fire() - ", exception })); } } } } return true; }
internal TimerQueue(int durationMilliseconds) : base(durationMilliseconds) { this.m_Timers = new TimerThread.TimerNode(); this.m_Timers.Next = this.m_Timers; this.m_Timers.Prev = this.m_Timers; }
internal override bool Cancel() { if (this.m_TimerState == TimerState.Ready) { lock (this.m_QueueLock) { if (this.m_TimerState == TimerState.Ready) { this.Next.Prev = this.Prev; this.Prev.Next = this.Next; this.Next = null; this.Prev = null; this.m_Callback = null; this.m_Context = null; this.m_TimerState = TimerState.Cancelled; return true; } } } return false; }