public static void CreateMainTimer(IConfigurationRoot configurationRoot) { #region Local Variables used inside .ctor string durationAsString; #endregion // Create the MainTimer // Duration is from configuration durationAsString = configurationRoot.GetValue <string>(StringConstantsVA.MainTimerTimeSpanConfigRootKey, StringConstantsVA.MainTimerTimeSpanDefault); TimeSpan durationAsTimeSpan; try { durationAsTimeSpan = TimeSpan.Parse(durationAsString); } catch (FormatException) { Serilog.Log.Debug("{0} {1}: durationAsString is {2} and cannot be parsed as a TimeSpan", "PluginVA", "Data(.ctor)", durationAsString); Data.StoredVAProxy.WriteToLog($"durationAsString is {durationAsString} and cannot be parsed as a TimeSpan", "Red"); throw new InvalidDataException($"durationAsString is {durationAsString} and cannot be parsed as a TimeSpan"); } catch (OverflowException) { Serilog.Log.Debug("{0} {1}: durationAsString is {2} and is outside the range of a TimeSpan", "PluginVA", "Data(.ctor)", durationAsString); Data.StoredVAProxy.WriteToLog($"durationAsString is {durationAsString} and is outside the range of a TimeSpan", "Red"); throw new InvalidDataException($"durationAsString is {durationAsString} and is outside the range of a TimeSpan"); } ObservableResetableTimersHostedServiceData.AddInterval(StringConstantsVA.MainTimerName, true, durationAsTimeSpan, GetMainTimerAction(durationAsTimeSpan)); // debug Data.ObservableResetableTimersHostedServiceData.TimerDisposeHandles[StringConstantsVA.MainTimerName].ActionList.Add() // Attach the action specified as a method parameter to the main timer // Data.TimerDisposeHandles[StringConstantsVA.MainTimerName].Subscribe(DoSomething); // Read MainCommandQueue and execute any Actions there }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // dispose of the ObservableResetableTimersHostedServiceData, which will handle disposing of any active timers ObservableResetableTimersHostedServiceData.Dispose(); } disposedValue = true; } }