浏览代码

resolve scheduled task write error

Luke Pulverenti 10 年之前
父节点
当前提交
47571bc5bd
共有 1 个文件被更改,包括 10 次插入7 次删除
  1. 10 7
      MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs

+ 10 - 7
MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs

@@ -121,12 +121,12 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
             {
                 if (_lastExecutionResult == null)
                 {
+                    var path = GetHistoryFilePath();
+
                     lock (_lastExecutionResultSyncLock)
                     {
                         if (_lastExecutionResult == null)
                         {
-                            var path = GetHistoryFilePath();
-
                             try
                             {
                                 return JsonSerializer.DeserializeFromFile<TaskResult>(path);
@@ -152,6 +152,14 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
             private set
             {
                 _lastExecutionResult = value;
+
+                var path = GetHistoryFilePath();
+                Directory.CreateDirectory(Path.GetDirectoryName(path));
+
+                lock (_lastExecutionResultSyncLock)
+                {
+                    JsonSerializer.SerializeToFile(value, path);
+                }
             }
         }
 
@@ -582,11 +590,6 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
                 result.LongErrorMessage = ex.StackTrace;
             }
 
-            var path = GetHistoryFilePath();
-            Directory.CreateDirectory(Path.GetDirectoryName(path));
-
-            JsonSerializer.SerializeToFile(result, path);
-
             LastExecutionResult = result;
 
             ((TaskManager)TaskManager).OnTaskCompleted(this, result);