Ejemplo n.º 1
0
        public ITaskResult CreateFuture(int dueTickTime, Func <ITaskResult> action, int priority)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("TaskFactory");
            }

            ManualTaskResult ret = new ManualTaskResult(_threadPool);

            ret.Start();

            var task = CreateFuture(dueTickTime, () =>
            {
                var next = action();

                if (next != null)
                {
                    next.Then(x =>
                    {
                        if (x.HasResult)
                        {
                            ret.SetResult(x.Result);
                        }
                        ret.SetCompleted();
                    }).Catch(error =>
                    {
                        ret.SetFailed(error);
                    });
                }
                else
                {
                    ret.SetCompleted();
                }
            }, priority).Catch(error =>
            {
                ret.SetFailed(error);
            });

            return(new BoundTaskResult(task, ret));
        }
Ejemplo n.º 2
0
        public ITaskResult Create(Func <ITaskResult> action)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("TaskFactory");
            }

            ManualTaskResult ret = new ManualTaskResult(_threadPool);

            ret.Start();

            var task = Create(() =>
            {
                var next = action();

                if (next != null)
                {
                    next.Then(x =>
                    {
                        if (x.HasResult)
                        {
                            ret.SetResult(x.Result);
                        }
                        ret.SetCompleted();
                    }).Catch(error =>
                    {
                        ret.SetFailed(error);
                    });
                }
                //else
                //{
                //    ret.SetCompleted();
                //}
            }).Catch(error =>
            {
                ret.SetFailed(error);
            });

            return(new BoundTaskResult(task, ret));
        }