Example #1
0
        /// <summary>
        /// </summary>
        /// <param name="task"></param>
        /// <param name="runOnMainThread"></param>
        /// <param name="cancelable"></param>
        public ProgressTask(Action <IProgressPromise <TProgress> > task, bool runOnMainThread = false,
                            bool cancelable = false)
        {
            if (task == null)
            {
                throw new ArgumentNullException();
            }

            result = new ProgressResult <TProgress>(!runOnMainThread && cancelable);
            result.Callbackable().OnProgressCallback(OnProgressChanged);
            if (runOnMainThread)
            {
                action = WrapAction(() =>
                {
                    Executors.RunOnMainThread(() => task(result), true);
                    result.Synchronized().WaitForResult();
                });
            }
            else
            {
                action = WrapAction(() =>
                {
                    task(result);
                    result.Synchronized().WaitForResult();
                });
            }
        }
Example #2
0
        /// <summary>
        ///     run on main thread.
        /// </summary>
        /// <param name="task"></param>
        /// <param name="cancelable"></param>
        public ProgressTask(Func <IProgressPromise <TProgress>, IEnumerator> task, bool cancelable = false)
        {
            if (task == null)
            {
                throw new ArgumentNullException();
            }

            result = new ProgressResult <TProgress>(cancelable);
            result.Callbackable().OnProgressCallback(OnProgressChanged);
            action = WrapAction(() =>
            {
                Executors.RunOnCoroutine(task(result), result);
                result.Synchronized().WaitForResult();
            });
        }