Beispiel #1
0
        /// <summary>
        /// Async method to cancel the operations
        /// </summary>
        public static async Task <TaskResult> CancelTaskAsync(SqlTask sqlTask)
        {
            ITaskOperation taskOperation = sqlTask.TaskMetadata.TaskOperation as ITaskOperation;
            TaskResult     taskResult    = null;

            if (taskOperation != null)
            {
                return(await Task.Factory.StartNew(() =>
                {
                    try
                    {
                        taskOperation.Cancel();

                        return new TaskResult
                        {
                            TaskStatus = SqlTaskStatus.Canceled
                        };
                    }
                    catch (Exception ex)
                    {
                        return new TaskResult
                        {
                            TaskStatus = SqlTaskStatus.Failed,
                            ErrorMessage = ex.Message
                        };
                    }
                }));
            }
            else
            {
                taskResult            = new TaskResult();
                taskResult.TaskStatus = SqlTaskStatus.Failed;
            }

            return(taskResult);
        }
Beispiel #2
0
 /// <summary>
 /// Starts the task and monitor the task progress
 /// </summary>
 public async Task RunAsync()
 {
     TaskStatus = SqlTaskStatus.InProgress;
     await RunAndCancel().ContinueWith(task =>
     {
         if (task.IsCompleted && !task.IsCanceled && !task.IsFaulted)
         {
             TaskResult taskResult = task.Result;
             TaskStatus            = taskResult.TaskStatus;
         }
         else if (task.IsCanceled)
         {
             TaskStatus = SqlTaskStatus.Canceled;
         }
         else if (task.IsFaulted)
         {
             TaskStatus = SqlTaskStatus.Failed;
             if (task.Exception != null)
             {
                 AddMessage(task.Exception.Message);
             }
         }
     });
 }