private void AddTask(bool im, Action <TaskGoEventArgs> go, Action <TaskAlertEventArgs> alert = null, Action <TaskProgressChangedEventArgs> progressChanged = null, Action <TaskStartedEventArgs> started = null, Action <TaskEndedEventArgs> ended = null, Action <TaskCompletedEventArgs> completed = null, Action <TaskStoppedEventArgs> stopped = null, Action <TaskTerminatedEventArgs> terminated = null, object userState = null) { var meta = new TaskDelegateMetadata() { Go = go, Terminated = terminated, Stopped = stopped, Started = started, Completed = completed, Ended = ended, ProgressChanged = progressChanged, Alert = alert, UserState = userState }; lock (tasks) { if (im) { tasks.Insert(0, meta); } else { tasks.Add(meta); } } lock (objSyncCount) if (cntThread < 1) { if (Pool == null) { ThreadWorkstaion.Start(new Action(() => TaskProc()), UseThreadPool); } else { Pool.Start(new Action(() => TaskProc()), UseThreadPool); } } }
private ITask CreateTask(TaskDelegateMetadata meta) { var task = Task.Create( go => { OnGo(meta, go); }, alert => { OnAlert(meta, alert); }, progressChanged => { OnProgressChanged(meta, progressChanged); }, started => { OnStarted(meta, started); }, ended => { OnEnded(meta, ended); }, completed => { OnCompleted(meta, completed); }, stopped => { OnStopped(meta, stopped); }, terminated => { OnTerminated(meta, terminated); }); task.Argument.UserState = meta.UserState; return(task); }
private ITask GetTask() { if (tasks.Count == 0) { return(null); } ITask task = null; lock (tasks) { TaskDelegateMetadata meta = null; if (tasks.Count != 0) { meta = tasks[0]; tasks.RemoveAt(0); task = CreateTask(meta); currentTask = task; } } return(task); }
protected virtual void OnGo(TaskDelegateMetadata meta, TaskGoEventArgs go) { throw new NotImplementedException(); }
protected virtual void OnAlert(TaskDelegateMetadata meta, TaskAlertEventArgs alert) { throw new NotImplementedException(); }
protected virtual void OnProgressChanged(TaskDelegateMetadata meta, TaskProgressChangedEventArgs progressChanged) { throw new NotImplementedException(); }
protected virtual void OnStarted(TaskDelegateMetadata meta, TaskStartedEventArgs started) { throw new NotImplementedException(); }
protected virtual void OnTerminated(TaskDelegateMetadata meta, TaskTerminatedEventArgs terminated) { throw new NotImplementedException(); }
public void DoImmediatelyWithInterruptCurrent(TaskDelegateMetadata meta) { Interrupt(); AddTask(true, meta.Go, meta.Alert, meta.ProgressChanged, meta.Started, meta.Ended, meta.Completed, meta.Stopped, meta.Terminated, meta.UserState); }
public void DoImmediately(TaskDelegateMetadata meta) { AddTask(true, meta.Go, meta.Alert, meta.ProgressChanged, meta.Started, meta.Ended, meta.Completed, meta.Stopped, meta.Terminated, meta.UserState); }