Esempio n. 1
0
        public void Ex3_EventDelegate()
        {
            ExEvent p = new ExEvent();

            // Register listeners
            p.OnChangeDelegate += (s, a) => Console.WriteLine("Event3 raised to method 1: {0}", a.Value);
            p.OnChangeDelegate += (s, a) => Console.WriteLine("Event3 raised to method 2: {0}", a.Value);

            // Raise event (sender, custom args)
            p.OnChangeDelegate(this, new MyArgs()
            {
                Value = 42
            });
        }
Esempio n. 2
0
        public void Ex4_EventAccessor()
        {
            ExEvent p = new ExEvent();

            // Register listeners
            p.OnChangeCustom += (s, a) => Console.WriteLine("Event4 raised to method 1: {0}", a.Value);
            p.OnChangeCustom += (s, a) => Console.WriteLine("Event4 raised to method 2: {0}", a.Value);

            // Raise event (sender, custom args)
            p.onChangeCustom(this, new MyArgs()
            {
                Value = 42
            });
        }
Esempio n. 3
0
        public void Ex4_EventException()
        {
            ExEvent p = new ExEvent();

            p.OnChangeEx += (sender, e) => Console.WriteLine("Sub 1 called");

            p.OnChangeEx += (sender, e) => { throw new Exception("Test exception"); };

            p.OnChangeEx += (sender, e) => Console.WriteLine("Sub 3 called");

            try
            {
                p.RaiseEx();
            }
            catch (AggregateException ex)
            {
                foreach (Exception e in ex.InnerExceptions)
                {
                    Console.WriteLine("Exception: {0}", e.InnerException.Message);
                }
            }
        }