예제 #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
 public static void StartAsync(this ITask source, ApartmentState state, bool validate = false)
 {
     ThreadWorkstaion.Start(new Action(() => { source.Start(validate); }), state);
 }