public PvcTask Task(string taskName, Action <Action> asyncTaskAction) { var task = new PvcTask(taskName, asyncTaskAction); this.LoadedTasks.Add(task); return(task); }
public PvcTask Task(string taskName, Action<Action> asyncTaskAction) { var task = new PvcTask(taskName, asyncTaskAction); this.LoadedTasks.Add(task); return task; }
private void RunTasks(PvcTask[] tasks) { for (int i = 0; i < tasks.Length; i++) { var task = tasks[i]; // lock on task name to avoid multiple threads doing the work lock (locks[task.taskName]) { try { if (CompletedTasks.Contains(task.taskName)) continue; if (task.isAsync) { // Start callback chain for async methods, lock on task Monitor.Enter(locks[task.taskName]); var callbackCalled = false; var stopwatch = this.StartTaskStatus(task.taskName); task.ExecuteAsync(() => { this.FinishTaskStatus(task.taskName, stopwatch); CompletedTasks.Add(task.taskName); if (i != tasks.Length - 1) this.RunTasks(tasks.Skip(i + 1).ToArray()); callbackCalled = true; }); // Keep app running while async task completes while (callbackCalled == false) { } break; } else { var stopwatch = this.StartTaskStatus(task.taskName); task.Execute(); CompletedTasks.Add(task.taskName); this.FinishTaskStatus(task.taskName, stopwatch); } } catch (Exception ex) { throw new PvcException(ex); } } } }