예제 #1
0
        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);
                    }
                }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 protected virtual void OnGo(TaskDelegateMetadata meta, TaskGoEventArgs go)
 {
     throw new NotImplementedException();
 }
예제 #5
0
 protected virtual void OnAlert(TaskDelegateMetadata meta, TaskAlertEventArgs alert)
 {
     throw new NotImplementedException();
 }
예제 #6
0
 protected virtual void OnProgressChanged(TaskDelegateMetadata meta, TaskProgressChangedEventArgs progressChanged)
 {
     throw new NotImplementedException();
 }
예제 #7
0
 protected virtual void OnStarted(TaskDelegateMetadata meta, TaskStartedEventArgs started)
 {
     throw new NotImplementedException();
 }
예제 #8
0
 protected virtual void OnTerminated(TaskDelegateMetadata meta, TaskTerminatedEventArgs terminated)
 {
     throw new NotImplementedException();
 }
예제 #9
0
 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);
 }
예제 #10
0
 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);
 }