public static async Task RunAsync()
        {
            var factory   = new EventFactory();
            var disruptor = new Disruptor <MyEvent>(factory, 1024, TaskScheduler.Default);

            var handler1 = new EventHandler1();
            var handler2 = new EventHandler2();
            var handler3 = new EventHandler3();

            disruptor.HandleEventsWith(handler1)
            .Then(handler2)
            .Then(handler3);

            await disruptor.StartAsync();
        }
Пример #2
0
        /// <summary>Reports a progress change.</summary>
        /// <param name="value">The value of the updated progress.</param>
        protected virtual void OnReport(T value)
        {
            // If there's no handler, don't bother going through the sync context.
            // Inside the callback, we'll need to check again, in case
            // an event handler is removed between now and then.
            Action2 <T>       handler      = _handler;
            EventHandler2 <T> changedEvent = ProgressChanged;

            if (handler != null || changedEvent != null)
            {
                // Post the processing to the sync context.
                // (If T is a value type, it will get boxed here.)
                _synchronizationContext.Post(_invokeHandlers, value);
            }
        }
Пример #3
0
        /// <summary>Invokes the action and event callbacks.</summary>
        /// <param name="state">The progress value.</param>
        private void InvokeHandlers(object state)
        {
            T value = (T)state;

            Action2 <T>       handler      = _handler;
            EventHandler2 <T> changedEvent = ProgressChanged;

            if (handler != null)
            {
                handler(value);
            }
            if (changedEvent != null)
            {
                changedEvent(this, value);
            }
        }
        //public void MyHandler(string message)
        //{
        //    Console.WriteLine("<my handler event>");
        //}

        public void TestEvent()
        {
            SomethingHappened += new EventHandlerVincent(delegate(string message)
            {
                Console.WriteLine("Event callback !!!!!");
            });
            SomethingHappened("Event Invoker....");

            SomethingHappened2 += new EventHandler2(delegate(int i)
            {
                Console.WriteLine("1st delegate " + i);
            });

            SomethingHappened2 += new EventHandler2(delegate(int i)
            {
                Console.WriteLine("2nd delegate " + i);
            });
            SomethingHappened2(7777777); //@20180109-vincent: This can't be called outside but delegate is allowed
        }
Пример #5
0
 public IDisposable Subscribe(EventHandler2 <AsyncProgressReportedEventArgs <T> > subscriber)
 => P_NopDisposable.Instance;
Пример #6
0
        private void TestBasicEvent()
        {
            EventHandler2 <EventArgs> handler = new EventHandler2 <EventArgs>(TestHandler);

            handler(new object(), EventArgs.Empty);
        }