public ITask Task(System.Func <object> task) { var taskRunner = new ThreadTask(this) { TaskWithResult = task, ReturnResult = true, }; return(taskRunner); }
public ITask Task(System.Action task) { var taskRunner = new ThreadTask(this) { Task = task, ReturnResult = false, }; return(taskRunner); }
public void Cancel(ThreadTask taskRunner) { taskRunnerLocker.EnterWriteLock(); try { this.taskRunner.Remove(taskRunner); }finally { taskRunnerLocker.ExitWriteLock(); } }
private void RunTaskThread(ThreadTask 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); }); } } }
public ITaskHandler AddTask(ThreadTask 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); } return(taskRunner); }
/// <summary> /// 添加任务 /// </summary> /// <param name="task">任务</param> /// <returns>任务句柄</returns> public ITaskHandler AddTask(ThreadTask task) { task.StartTime = Time.Time; if (task.DelayTime > 0) { taskRunnerLocker.EnterWriteLock(); try { taskRunner.Add(task); } finally { taskRunnerLocker.ExitWriteLock(); } } else { ThreadPool.QueueUserWorkItem(ThreadExecuter, task); } return(task); }