public KancolleTaskResult(KancolleTask finishedTask, KancolleTaskResultType type, string message, int errorcode) { FinishedTask = finishedTask; ResultType = type; Message = message; ErrorCode = errorcode; }
/// <summary> /// 执行task,改函数进程阻塞,等到该任务被执行并返回结果。 /// 如果当前已经有任务正在执行,那么直接返回fail。 /// 线程不安全! /// </summary> /// <param name="task"></param> /// <returns>执行结果</returns> public KancolleTaskResult DoTask(KancolleTask task) { //始终保持只有1个task在运行 if (TaskRemaining > 0 || RunningTask != null) { var result = new KancolleTaskResult(task, KancolleTaskResultType.Fail, "当前正在执行其他任务!", ExistRunningTask); OnTaskFinished(this, result); return(result); } LastResult = null; EnqueueTask(task); while (LastResult == null) { Thread.Sleep(500); } return(LastResult); }
/// <summary> /// 在优先级队列中插入一个新的任务,该任务会在合适的时机被执行 /// 该函数将不再对外可用 /// </summary> /// <param name="task"></param> private void EnqueueTask(KancolleTask task) { taskQueue.Enqueue(task, (int)task.Priority); OnTaskChanged?.InvokeAll(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, task)); }