Пример #1
0
        public static CancellationTokenSource ExecuteActionsAsync(ConcurrentExecutionDispatcher actions)
        {
            var cancellationTokenSource = new CancellationTokenSource();

              ThreadPool.QueueUserWorkItem(x =>
              {
            actions.Run(cancellationTokenSource.Token);
              });
              return cancellationTokenSource;
        }
Пример #2
0
        public static CancellationTokenSource ExecuteActionsAsync(ConcurrentExecutionDispatcher actions)
        {
            var cancellationTokenSource = new CancellationTokenSource();

            ThreadPool.QueueUserWorkItem(x =>
            {
                actions.Run(cancellationTokenSource.Token);
            });
            return(cancellationTokenSource);
        }
Пример #3
0
        static void Main(string[] args)
        {
            var actionQueue = new ConcurrentExecutionDispatcher(e => { Console.Error.WriteLine(e.ToString()); });
              var calculator = BeginInvokeProxy<ICalculator>.Create(new Calculator(), actionQueue);

              var cancellationTokenSource = ExecuteActionsAsync(actionQueue);

              calculator.SetValue(5);
              for (int i = 0; i < 100; i++)
              {
            calculator.Inc();
            calculator.Sub();
              }
              calculator.Inc();
              calculator.Sub();

              Console.WriteLine(calculator.Result());

              cancellationTokenSource.Cancel();

              Console.ReadKey();
        }
Пример #4
0
        static void Main(string[] args)
        {
            var actionQueue = new ConcurrentExecutionDispatcher(e => { Console.Error.WriteLine(e.ToString()); });
            var calculator  = BeginInvokeProxy <ICalculator> .Create(new Calculator(), actionQueue);

            var cancellationTokenSource = ExecuteActionsAsync(actionQueue);

            calculator.SetValue(5);
            for (int i = 0; i < 100; i++)
            {
                calculator.Inc();
                calculator.Sub();
            }
            calculator.Inc();
            calculator.Sub();


            Console.WriteLine(calculator.Result());

            cancellationTokenSource.Cancel();


            Console.ReadKey();
        }