// Do not declare virtual events in a base class and override them in a derived class.
        // The C# compiler does not handle these correctly and it is unpredictable whether a subscriber
        // to the derived event will actually be subscribing to the base class event.
        protected override void OnCustomEventWithGenerics(CustomEventArgs e)
        {
            // Execute some specific logic
            e = new CustomEventArgs(e.Message + " - in the override.");

            base.OnCustomEventWithGenerics(e);
        }
Beispiel #2
0
 //Subscriber has same method signature as publisher
 public void ConsumeNewCarInformationFromPublisher(object obj, CustomEventArgs eventArgs)
 {
     Console.WriteLine("Subscriber {0} found this car from publisher: {1}", consumerName, eventArgs.Car);
 }
 protected virtual void OnCustomEventWithGenerics(CustomEventArgs e)
 {
     EventHandler<CustomEventArgs> handler = CustomEventWithGenerics;
     if (handler != null) handler(this, e);
 }
 public void DoCustomWork(CustomEventArgs a)
 {
     CustomEventHandler handler = CustomEvent;
     if (handler != null) handler(this, a);
 }
Beispiel #5
0
 // Define what actions to take when the event is raised.
 void HandleCustomEvent(object sender, CustomEventArgs e)
 {
     Console.WriteLine(id + " received this message: {0}", e.Message);
 }