Example #1
0
            private void Call()
            {
                TimerInfo timerInfo  = _timerInfo;
                object    syncObject = default(object);

                try
                {
                    bool lockTaken = false;
                    try
                    {
                        Monitor.Enter(syncObject = timerInfo.SyncObject, ref lockTaken);
                        timerInfo.IsRuning       = true;
                        timerInfo.IsReady        = false;
                    }
                    finally
                    {
                        if (lockTaken)
                        {
                            Monitor.Exit(syncObject);
                        }
                    }
                    timerInfo.LastBeginTime = TickCount;
                    timerInfo.Callback();
                    timerInfo.LastEndTime = TickCount;
                    _timerInfo            = null;
                }
                catch (Exception ex)
                {
                    if (!(timerInfo?.IsFree ?? true))
                    {
                        timerInfo.IsError     = true;
                        timerInfo.Error       = ex;
                        timerInfo.LastEndTime = TickCount;
                        OnError(ex);
                    }
                    _timerInfo = null;
                }
                finally
                {
                    if (!(timerInfo?.IsFree ?? true))
                    {
                        bool lockTaken2 = false;
                        try
                        {
                            Monitor.Enter(syncObject = timerInfo.SyncObject, ref lockTaken2);
                            timerInfo.IsRuning       = false;
                            timerInfo.TimerThread    = null;
                        }
                        finally
                        {
                            if (lockTaken2)
                            {
                                Monitor.Exit(syncObject);
                            }
                        }
                    }
                }
            }