public ITask Task(System.Action task) { var taskRunner = new TaskRunner(this) { Task = task, ReturnResult = false, }; return taskRunner; }
public ITask Task(System.Func<object> task) { var taskRunner = new TaskRunner(this) { TaskWithResult = task, ReturnResult = true, }; return taskRunner; }
public void AddTask(TaskRunner taskRunner) { taskRunner.StartTime = App.Time.Time; if (taskRunner.DelayTime > 0) { taskRunnerLocker.EnterWriteLock(); try { this.taskRunner.Add(taskRunner); } finally { taskRunnerLocker.ExitWriteLock(); } } else { ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadExecuter), taskRunner); } }
private void RunTaskThread(TaskRunner taskRunner) { try { object result = null; if (taskRunner.ReturnResult) { result = taskRunner.TaskWithResult(); } else { taskRunner.Task(); } if (taskRunner.Complete != null) { App.MainThread(() => { taskRunner.Complete(); }); } if (taskRunner.CompleteWithResult != null) { App.MainThread(() => { taskRunner.CompleteWithResult(result); }); } } catch (System.Exception exception) { if (taskRunner.Error != null) { App.MainThread(() => { taskRunner.Error(exception); }); } } }