Пример #1
0
        public Task ServerMethodThatReturnsCustomTask()
        {
            var result = new CustomTask();

            result.Start();
            return(result);
        }
        public CustomTask ReturnsCustomTask()
        {
            _workload.BeforeReturningAwaitable();
            _workload.BeforeReturningAwaiter();

            var task = new CustomTask(() => _workload.GetResult());

            if (_workload.IsCompleted)
            {
                task.Start();
            }
            else
            {
                _workload.OnCompleted(task.Start);
            }

            return(task);
        }
Пример #3
0
            static void Main(string[] args)
            {
                CustomTask antecedent = new CustomTask(
                    () =>
                    {
                        throw new Exception("Unhandled");
                    });
                antecedent.ContinueWith(

                    (predTask) =>
                    {
                        ((CustomTask)predTask).PerformRollback();
                    },
                    TaskContinuationOptions.OnlyOnFaulted);

                antecedent.Start();
                try
                {
                    antecedent.Wait();
                }
                catch (AggregateException ex)
                {
                }
            }