예제 #1
0
        static async Task Main(string[] args)
        {
            var behaviorContext = new BehaviorContext();

            var behaviors = new IBehavior[] {
                new MyBehavior1(),
                new MyBehavior2(),
                new CancelBehavior(),
            };

            var pipeline = behaviors.CreatePipelineExecutionFuncFor <BehaviorContext>();

            Console.WriteLine("Execute 1");
            await pipeline(behaviorContext, new CancellationToken(false));

            try
            {
                Console.WriteLine("Execute 2 with Cancellation");
                await pipeline(behaviorContext, new CancellationToken(true));
            }
            catch (OperationCanceledException)
            {
                Console.WriteLine("Canceled");
            }
            try
            {
                Console.WriteLine();
                Console.WriteLine("Execute 2 with Cancellation");
                await pipeline(behaviorContext, new CancellationToken(true));
            }
            catch (OperationCanceledException)
            {
                Console.WriteLine("Canceled");
            }

            Console.WriteLine();
            Console.WriteLine("Execute 4");
            await pipeline(behaviorContext, new CancellationToken(false));

            Console.ReadLine();
        }