public void Run() { Console.WriteLine("EventSource Example (.NET Core 1.0)"); var customEventSource = new CustomEventSource(); customEventSource.Information("Test .NET Core 1.0"); }
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 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 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(); }
public static void RemoveListener(CustomEventSource source, IWeakEventListener listener) { CurrentManager.ProtectedRemoveListener(source, listener); }