Ejemplo n.º 1
0
        /// <summary>
        /// Timer triggered; run the executor.
        /// </summary>
        private void OnTimer()
        {
            try
            {
                TimerTriggerResult tr = null;
                lock (_lock)
                {
                    _timer.Change(Timeout.Infinite, Timeout.Infinite);
                    tr = OnTrigger() ?? throw new InvalidOperationException("OnTrigger override must return a TimerTriggerResult instance.");
                    Trace(() => Logger.Default.Trace($"Trigger '{InstanceId}' timer has fired; Executor run enabled: {tr.IsExecutorRunEnabled}."));
                }

                if (tr.IsExecutorRunEnabled)
                {
                    Run(() => RestartTimer());
                }
                else
                {
                    RestartTimer();
                }
            }
            catch (Exception ex)
            {
                Logger.Default.Exception(ex, $"Trigger '{InstanceId}' encountered an exception whilst executing OnTimer: {ex.Message}");
                Stop(ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Timer triggered; run the executor.
        /// </summary>
        private void OnTimer()
        {
            try
            {
                TimerTriggerResult <TArgs> tr = null;
                lock (_lock)
                {
                    _timer.Change(Timeout.Infinite, Timeout.Infinite);
                    tr = OnTrigger() ?? throw new InvalidOperationException("OnTrigger override must return a TimerTriggerResult instance.");
                    Trace(() => Logger.Default.Trace($"Trigger '{InstanceId}' timer has fired; Executor run enabled: {tr.IsExecutorRunEnabled}."));
                }

                if (tr.IsExecutorRunEnabled)
                {
                    Run(tr.Args, () => RestartTimer());
                }
                else
                {
                    RestartTimer();
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types; by-design, bubbles out internally.
            catch (Exception ex)
            {
                Logger.Default.Exception(ex, $"Trigger '{InstanceId}' encountered an exception whilst executing OnTimer: {ex.Message}");
                Stop(ex);
            }
#pragma warning restore CA1031
        }