/// <summary>
        /// Executes code on the background thread.
        /// </summary>
        /// <param name="backgroundAction">The background action.</param>
        /// <param name="uiCallback">The UI callback.</param>
        /// <param name="progressChanged">The progress change callback.</param>
        public IBackgroundTask ExecuteOnBackgroundThread(Action backgroundAction, Action<BackgroundTaskCompletedEventArgs> uiCallback, Action<BackgroundTaskProgressChangedEventArgs> progressChanged)
        {
            var task = new BackgroundTask(
                _threadPool,
                () =>{
                    backgroundAction();
                    return null;
                });

            if (uiCallback != null)
                task.Completed += (s, e) => ExecuteOnUIThread(() => uiCallback(e));

            if (progressChanged != null)
                task.ProgressChanged += (s, e) => ExecuteOnUIThread(() => progressChanged(e));

            task.Enqueue(null);

            return task;
        }
示例#2
0
        /// <summary>
        /// Executes code on the background thread.
        /// </summary>
        /// <param name="backgroundAction">The background action.</param>
        /// <param name="uiCallback">The UI callback.</param>
        /// <param name="progressChanged">The progress change callback.</param>
        public IBackgroundTask ExecuteOnBackgroundThread(Action backgroundAction, Action <BackgroundTaskCompletedEventArgs> uiCallback, Action <BackgroundTaskProgressChangedEventArgs> progressChanged)
        {
            var task = new BackgroundTask(
                _threadPool,
                () => {
                backgroundAction();
                return(null);
            });

            if (uiCallback != null)
            {
                task.Completed += (s, e) => ExecuteOnUIThread(() => uiCallback(e));
            }

            if (progressChanged != null)
            {
                task.ProgressChanged += (s, e) => ExecuteOnUIThread(() => progressChanged(e));
            }

            task.Enqueue(null);

            return(task);
        }