示例#1
0
        /// <summary>
        /// Run asynchronously a task in another thread. You can report at any time the state of your background task
        /// through the <see cref="IBackgroundTask"/> interface given in onWork function parameter.
        /// The report callback is send in the main ui thread.
        /// </summary>
        /// <typeparam name="TResult">Background work result type.</typeparam>
        /// <param name="manager"><see cref="IBackgroundTaskManager"/> which is extended.</param>
        /// <param name="onWork">Function which is executed asyncronously. The parameter allows you to report the state of the background work.</param>
        /// <param name="onCompleted">Callback called in the main ui thread when the work is finished. We provide the result as parameter.</param>
        public static void Dispatch <TResult>(this IBackgroundTaskManager manager, Func <IBackgroundTask, TResult> onWork, Action <TResult> onCompleted = null)
        {
            if (onWork == null)
            {
                return;
            }

            manager.Dispatch(
                (t, s) => onWork(t),
                onCompleted != null ? (r, s) => onCompleted(r) : (Action <TResult, object>)null);
        }
示例#2
0
        /// <summary>
        /// Run asynchronously a task in another thread with an indeterminate time of work.
        /// </summary>
        /// <param name="manager"><see cref="IBackgroundTaskManager"/> which is extended.</param>
        /// <param name="onWork">Function which is executed asyncronously.</param>
        /// <param name="onCompleted">Callback called in the main ui thread when the work is finished.</param>
        public static void Dispatch(this IBackgroundTaskManager manager, Action onWork, Action onCompleted = null)
        {
            if (onWork == null)
            {
                return;
            }

            manager.Dispatch(
                (t, s) =>
            {
                onWork();
                return(null);
            },
                onCompleted != null ? (r, s) => onCompleted() : (Action <object, object>)null);
        }