private void OnRaiseWeirdEvent(int data)
        {
            EventHandler <WeirdEventArgs> handler = _raiseWeirdEvent;
            int eventBeingFired = 1;

            if (handler != null)
            {
                // We iterate over each internal handler.
                // Then construct special event arguments for each call
                // Which will pass in the specific event number being
                // fired.
                //
                // Since these are invoked sequentially, it would also
                // be possible to use a single instance of WeirdEventArgs
                // and then modify EventNumberInvoked prior to each call.
                foreach (EventHandler <WeirdEventArgs> item in handler.GetInvocationList())
                {
                    var args = new WeirdEventArgs()
                    {
                        State              = data,
                        NumEvents          = _numberOfEvents,
                        EventNumberInvoked = eventBeingFired++,
                    };

                    Console.WriteLine($"Invoking WeirdEvent: data={data}; event={eventBeingFired}");
                    item(this, args);
                }
            }
        }
Exemple #2
0
 private static void PerformWeirdProcess2(object sender, WeirdEventArgs e)
 {
     Console.WriteLine($"Performing Weird Process 2: data={e.State}; event={e.EventNumberInvoked}");
 }