public static void Test() { var source = new PropertyChangedEventSource(); var listener = new PropertyChangedEventEventListener(); //Register listener to the source PropertyChangedEventManager.AddListener(source, listener, nameof(PropertyChangedEventSource.Name)); //change property change and the ReceiveWeakEvent of PropertyChangedEventEventListener method will be called source.Name = "first name"; //set listener to null so it will be ready for gc listener = null; //trigger gc and the listener will be collected. GCUtils.TriggerGC(); //change property value but the ReceiveWeakEvent of PropertyChangedEventEventListener method will NOT be called source.Name = "second name"; Console.Read(); }
public static void Test() { var eventSource = new CustomEventSource(); var listener = new CustomEventListener(); //register event listener eventSource.CustomEvent += listener.HandleEvent; //trigger event and listener.HandleEvent will be executed eventSource.Raise("First Message from CustomEventSource"); //set listener to null listener = null; //trigger gc but the listener object will NOT collected. GCUtils.TriggerGC(); //trigger event and listener.HandleEvent stil will be executed eventSource.Raise("Second Message from CustomEventSource"); Console.Read(); }
public static void Test() { var eventSource = new CustomEventSource(); var listener = new CustomEventListener(); //add handler listener.HandleEvent to CustomEvent of CustomEventSource WeakEventManager <CustomEventSource, CustomEventArg> .AddHandler(eventSource, "CustomEvent", listener.HandleEvent); //trigger event and listener.HandleEvent will be executed eventSource.Raise("First message"); //set listener to null listener = null; //trigger gc and the listener object will be collected. GCUtils.TriggerGC(); //trigger event and listener.HandleEvent stil will NOT be executed eventSource.Raise("Second Message"); Console.Read(); }
public static void Test() { var eventSource = new CustomEventSource(); var listener = new CustomWeakEventListener(); //add listener for eventSource via CustomizedWeakEventManager CustomizedWeakEventManager.AddListener(eventSource, listener); //trigger event and listener.ReceiveWeakEvent will be executed eventSource.Raise("First message"); //set listener to null listener = null; //trigger gc and the listener object will be collected. GCUtils.TriggerGC(); //trigger event and listener.HandleEvent stil will NOT be executed eventSource.Raise("Second Message"); Console.Read(); }