コード例 #1
0
        /// <summary>
        /// Starts the task.
        /// </summary>
        /// <param name="task">The task.</param>
        public void StartTask(ITask task)
        {
#if !WINDOWS_PHONE
            Task t = new Task(task.Process);
            if (task.TaskEndType == TaskEndType.INSTANT)
            {                
                t.BeginInvoke(new AsyncCallback(task.Result), null);                
            }
            else if (task.TaskEndType == TaskEndType.ON_NEXT_UPDATE)
            {                
                t.BeginInvoke(new AsyncCallback(onfinished), task);                
            }
#else
         Worker worker = new Worker();
         worker.DoWork+=new System.ComponentModel.DoWorkEventHandler(                          
             (a,b)=> task.Process()
        );

         if (task.TaskEndType == TaskEndType.INSTANT)
         {
             worker.RunWorkerCompleted+=new System.ComponentModel.RunWorkerCompletedEventHandler(
                 (a, b) => task.Result()
                     );
         }
         else if (task.TaskEndType == TaskEndType.ON_NEXT_UPDATE)
         {
             worker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(
                 (a, b) =>
                 {
                     if (b.Error != null)
                     {
                         ActiveLogger.LogMessage("Thread finished with errors " + b.Error.ToString(), LogLevel.RecoverableError);
                         return;
                     }
                     lock (finished)
                     {
                         finished.Add(task);
                     }
                 }
                 );
         }       
          
          worker.RunWorkerAsync();
#endif
        }
コード例 #2
0
 void taskSample_Ended(ITask arg1, IAsyncResult arg2)
 {
     ended = true;
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskCommand"/> class.
 /// </summary>
 /// <param name="task">The task.</param>
 public TaskCommand(ITask task)
 {
     this.task = task;
 }