Exemplo n.º 1
0
        public ProgressTask(Action <IProgressPromise <TProgress> > task, bool runOnMainThread = false,
                            bool cancelable = false)
        {
            if (task == null)
            {
                throw new ArgumentNullException();
            }

            this._result = new ProgressResult <TProgress>(!runOnMainThread && cancelable);
            this._result.Callbackable().OnProgressCallback(OnProgressChanged);
            if (runOnMainThread)
            {
                this._action = WrapAction(() =>
                {
                    Executors.RunOnMainThread(() => task(_result), true);
                    _result.Synchronized().WaitForResult();
                });
            }
            else
            {
                this._action = WrapAction(() =>
                {
                    task(_result);
                    _result.Synchronized().WaitForResult();
                });
            }
        }
Exemplo n.º 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();
            }

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