コード例 #1
0
ファイル: Task.cs プロジェクト: citizenmatt/gallio
        /// <summary>
        /// Starts running the task.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Does nothing if the task has already been started or has been aborted.
        /// </para>
        /// </remarks>
        /// <seealso cref="IsPending"/>
        public void Start()
        {
            lock (sequenceLock)
            {
                if (!IsPending)
                {
                    return;
                }
                isStarted = true;

                try
                {
                    try
                    {
                        StartImpl();
                    }
                    finally
                    {
                        OnStarted();
                    }
                }
                catch (Exception ex)
                {
                    NotifyTerminated(TaskResult <object> .CreateFromException(ex));
                }
            }
        }
コード例 #2
0
        private void Run()
        {
            try
            {
                try
                {
                    try
                    {
                        BeforeTask();

                        ThreadAbortException ex = threadAbortScope.Run(invoker.Invoke);

                        if (ex != null)
                        {
                            NotifyTerminated(TaskResult <object> .CreateFromException(ex));
                        }
                        else
                        {
                            NotifyTerminated(TaskResult <object> .CreateFromValue(invoker.Result));
                        }
                    }
                    finally
                    {
                        AfterTask();
                    }
                }
                catch (Exception ex)
                {
                    NotifyTerminated(TaskResult <object> .CreateFromException(ex));
                }
            }
            catch (Exception ex)
            {
                UnhandledExceptionPolicy.Report("An unhandled exception occurred in a thread task.", ex);
            }
        }