Exemple #1
0
 public ITask Task(System.Action task)
 {
     var taskRunner = new TaskRunner(this)
     {
         Task = task,
         ReturnResult = false,
     };
     return taskRunner;
 }
Exemple #2
0
        public ITask Task(System.Func<object> task)
        {
            var taskRunner = new TaskRunner(this)
            {
                TaskWithResult = task,
                ReturnResult = true,
            };

            return taskRunner;
        }
Exemple #3
0
 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);
     }
 }
Exemple #4
0
        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);
                    });
                }
            }
        }