diff options
Diffstat (limited to 'MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs')
| -rw-r--r-- | MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 5e9038500..b09cb7105 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -108,13 +108,9 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// </summary> private TaskResult _lastExecutionResult; /// <summary> - /// The _last execution resultinitialized - /// </summary> - private bool _lastExecutionResultinitialized; - /// <summary> /// The _last execution result sync lock /// </summary> - private object _lastExecutionResultSyncLock = new object(); + private readonly object _lastExecutionResultSyncLock = new object(); /// <summary> /// Gets the last execution result. /// </summary> @@ -123,38 +119,39 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks { get { - LazyInitializer.EnsureInitialized(ref _lastExecutionResult, ref _lastExecutionResultinitialized, ref _lastExecutionResultSyncLock, () => + if (_lastExecutionResult == null) { - var path = GetHistoryFilePath(); - - try - { - return JsonSerializer.DeserializeFromFile<TaskResult>(path); - } - catch (DirectoryNotFoundException) - { - // File doesn't exist. No biggie - return null; - } - catch (FileNotFoundException) - { - // File doesn't exist. No biggie - return null; - } - catch (Exception ex) + lock (_lastExecutionResultSyncLock) { - Logger.ErrorException("Error deserializing {0}", ex, path); - return null; + if (_lastExecutionResult == null) + { + var path = GetHistoryFilePath(); + + try + { + return JsonSerializer.DeserializeFromFile<TaskResult>(path); + } + catch (DirectoryNotFoundException) + { + // File doesn't exist. No biggie + } + catch (FileNotFoundException) + { + // File doesn't exist. No biggie + } + catch (Exception ex) + { + Logger.ErrorException("Error deserializing {0}", ex, path); + } + } } - }); + } return _lastExecutionResult; } private set { _lastExecutionResult = value; - - _lastExecutionResultinitialized = value != null; } } @@ -227,13 +224,9 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// </summary> private IEnumerable<ITaskTrigger> _triggers; /// <summary> - /// The _triggers initialized - /// </summary> - private bool _triggersInitialized; - /// <summary> /// The _triggers sync lock /// </summary> - private object _triggersSyncLock = new object(); + private readonly object _triggersSyncLock = new object(); /// <summary> /// Gets the triggers that define when the task will run /// </summary> @@ -243,7 +236,16 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks { get { - LazyInitializer.EnsureInitialized(ref _triggers, ref _triggersInitialized, ref _triggersSyncLock, LoadTriggers); + if (_triggers == null) + { + lock (_triggersSyncLock) + { + if (_triggers == null) + { + _triggers = LoadTriggers(); + } + } + } return _triggers; } @@ -262,8 +264,6 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks _triggers = value.ToList(); - _triggersInitialized = true; - ReloadTriggerEvents(false); SaveTriggers(_triggers); |
