PRoConEvents.MULTIbalancer.TimerLoop C# (CSharp) Method

TimerLoop() private method

private TimerLoop ( ) : void
return void
        private void TimerLoop()
        {
            /*
            Strategy: Every 1/2 second, check the list of timers to see if any
            actions need to be fired.
            */
            try {
            while (fIsEnabled) {
            lock (fTimerRequestList) {
                Monitor.Wait(fTimerRequestList, 500); // 1/2 second max heartbeat
                if (!fIsEnabled) {
                    fTimerRequestList.Clear();
                    return;
                }

                // Time to check all requests
                DebugWrite("Checking " + fTimerRequestList.Count + " requests", 9);
                DateTime now = DateTime.Now;
                foreach (DelayedRequest request in fTimerRequestList) {
                    DebugWrite("Request: " + request.Name + ", " + now.Subtract(request.LastUpdate).TotalSeconds.ToString("F1") + " of " + request.MaxDelay + " seconds", 9);
                    if (now.Subtract(request.LastUpdate).TotalSeconds >= request.MaxDelay) {
                        try {
                            if (request.Request != null) {
                                if (DebugLevel >= 8) ConsoleDebug("Executing request: " + request.Name);
                                request.Request(now);
                            }
                        } catch (Exception e) {
                            if (DebugLevel >= 9) ConsoleException(e);
                        }
                        request.LastUpdate = now;
                    }
                }
            }
            }
            } catch (ThreadAbortException) {
            fAborted = true;
            return;
            } catch (Exception e) {
            ConsoleException(e);
            } finally {
            if (!fAborted) ConsoleWrite("^bTimerLoop^n thread stopped", 0);
            }
        }
MULTIbalancer