/// <summary> /// This method is called by _taskTimer. /// </summary> /// <param name="state">Not used argument</param> private void TimerCallBack(object state) { lock (_timer) { if (!_isRunning || _performingTasks) { return; } _timer.Change(Timeout.Infinite, Timeout.Infinite); _performingTasks = true; } try { Elapsed.InvokeSafely(this, new EventArgs()); } catch { } finally { lock (_timer) { _performingTasks = false; if (_isRunning) { _timer.Change(Period, Timeout.Infinite); } Monitor.Pulse(_timer); } } }
/// <summary> /// _taskTimer调用 /// </summary> /// <param name="state">暂未使用该参数</param> private void TimerCallBack(object state) { lock (_taskTimer) { if (!_isRunning || _performingTasks) { return; } _taskTimer.Change(Timeout.Infinite, Timeout.Infinite); _performingTasks = true; } try { Elapsed.InvokeSafely(this, new EventArgs()); } catch (Exception ex) { Logger.LogException(ex); AsyncHelper.RunSync(() => ExceptionNotifier.NotifyAsync(ex)); } finally { lock (_taskTimer) { _performingTasks = false; if (_isRunning) { _taskTimer.Change(Period, Timeout.Infinite); } Monitor.Pulse(_taskTimer); } } }