Beispiel #1
0
        void InitializeTask()
        {
            TimeOutInMilliseconds                 = 1000 * 30;
            TaskWorker                            = new AbortableBackgroundWorker();
            TaskWorker.WorkerReportsProgress      = true;
            TaskWorker.WorkerSupportsCancellation = true;
            TaskWorker.RunWorkerCompleted        += BackgroundTask_RunWorkerCompleted;
            TaskWorker.ProgressChanged           += BackgroundTask_ProgressChanged;

            TimeOutClock = new Stopwatch();
        }
Beispiel #2
0
        //------------------------------------------------------------------------------------
        /// <summary>
        /// Will be called when the commit thread completes (or successfully responds to a
        /// cancellation request).
        /// </summary>
        //------------------------------------------------------------------------------------
        void BackgroundTask_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            AbortableBackgroundWorker worker = sender as AbortableBackgroundWorker;

            if (worker.IsAborted)
            {
                if (TaskCompleted != null)
                {
                    TaskCompleted(TaskArgs, new BackgroundTaskResult {
                        Task = this, ResultType = ResultType.Cancelled
                    });
                }
            }
            else
            {
                if (ProgressDialog != null)
                {
                    ProgressDialog.CancelRequested -= ProgressDialog_CancelRequested;

                    if (ProgressDialogOption != PlannerNameSpace.ProgressDialogOption.StandardProgressNoClose)
                    {
                        ProgressDialog.CloseDialog();
                    }
                }

                if (e.Cancelled)
                {
                    if (TaskCompleted != null)
                    {
                        TaskCompleted(TaskArgs, new BackgroundTaskResult {
                            Task = this, ResultType = ResultType.Cancelled
                        });
                    }
                }
                else
                {
                    BackgroundTaskResult result = e.Result as BackgroundTaskResult;
                    if (result != null)
                    {
                        result.Task = this;
                    }

                    if (result != null && result.ResultType == ResultType.Failed)
                    {
                        Planner.Instance.HandleFailedTask(result);
                    }

                    if (TaskCompleted != null)
                    {
                        TaskCompleted(TaskArgs, result);
                    }
                }
            }
        }