예제 #1
0
 protected void ExecuteTask(SaveTask task)
 {
     try
     {
         task.Execute();
     }
     finally
     {
         // 保证数据同步
         Volatile.Write(ref _currentTaskFinished, true);
     }
 }
예제 #2
0
 /// <summary>
 /// 需要外部调用,用于检测异步执行的存档操作是否完成
 /// </summary>
 public void Update()
 {
     if (_currentTask != null)
     {
         // 保证数据同步
         if (Volatile.Read(ref _currentTaskFinished))
         {
             if (_currentTask.type == TaskType.LOAD && _currentTask.isSuccess)
             {
                 _currentTask.source.Write(_currentTask.data);
             }
             OnFinishTask(_currentTask);
             _currentTask = null;
         }
     }
     else if (_taskQueue.Count > 0)
     {
         _currentTask         = _taskQueue.Dequeue();
         _currentTaskFinished = false;
         OnBeginTask(_currentTask);
     }
 }
예제 #3
0
 protected abstract void OnFinishTask(SaveTask task);
예제 #4
0
 protected abstract void OnBeginTask(SaveTask task);
예제 #5
0
 public void NewDeleteTask(IStorageTarget target)
 {
     CheckDispos();
     _taskQueue.Enqueue(SaveTask.CreateDeleteTask(target));
 }
예제 #6
0
 public void NewSaveTask(IStorageSource source, IStorageTarget target)
 {
     CheckDispos();
     _taskQueue.Enqueue(SaveTask.CreateSaveTask(target, source.Read()));
 }
예제 #7
0
 public void NewLoadTask(IStorageSource source, IStorageTarget target)
 {
     CheckDispos();
     _taskQueue.Enqueue(SaveTask.CreateLoadTask(source, target));
 }