示例#1
0
        /// <summary>
        /// Creates and executes a new <see cref="BackgroundTask"/> based on the specified arguments.
        /// </summary>
        /// <param name="method">The method to run in the background.</param>
        /// <param name="supportsCancel">Indicates whether the task supports cancellation or not.</param>
        /// <param name="terminateHandler">Method that will be called when the task terminates.</param>
        /// <param name="progressHandler">Optional method to handle progress updates, may be null.</param>
        /// <param name="userState">Optional state to be passed to the background task, may be null.</param>
        /// <returns>A running <see cref="BackgroundTask"/> object.</returns>
        public static BackgroundTask CreateAndRun(
            BackgroundTaskMethod method,
            bool supportsCancel,
            EventHandler <BackgroundTaskTerminatedEventArgs> terminateHandler,
            EventHandler <BackgroundTaskProgressEventArgs> progressHandler,
            object userState)
        {
            Platform.CheckForNullReference(method, "method");
            Platform.CheckForNullReference(terminateHandler, "terminateHandler");

            var task = new BackgroundTask(method, supportsCancel, userState);

            task.Terminated += terminateHandler;
            if (progressHandler != null)
            {
                task.ProgressUpdated += progressHandler;
            }
            task.Run();
            return(task);
        }
示例#2
0
 public BackgroundTaskContext(BackgroundTask owner, DoWorkEventArgs doWorkArgs)
 {
     _owner      = owner;
     _doWorkArgs = doWorkArgs;
 }