-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weak Event (c#) #440
Comments
Show of problem with event. using System;
namespace WeakEventsDemo
{
class Program
{
static void Main()
{
Console.WriteLine("[Main] started");
Console.WriteLine("[Main] DemoPublisher_NoEvent");
DemoPublisher_NoEvent();
Console.WriteLine("[Main] DemoPublisher_Event_LocalSubscriber");
DemoPublisher_Event_LocalSubscriber();
Console.WriteLine("[Main] DemoPublisher_Event_GlobalSubscriber");
DemoPublisher_Event_GlobalSubscriber();
Console.WriteLine("[Main] Demo finished, Let's call GC");
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine("[Main] finished");
}
private static void DemoPublisher_NoEvent()
{
Publisher publisher = new Publisher();
publisher.Run();
}
private static void DemoPublisher_Event_LocalSubscriber()
{
Subscriber subscriber = new Subscriber("local");
Publisher publisher = new Publisher();
publisher.MyEvent += subscriber.EventProcessing;
publisher.Run();
}
private static readonly Subscriber m_globalSubscriber = new Subscriber("global");
private static void DemoPublisher_Event_GlobalSubscriber()
{
Publisher publisher = new Publisher();
publisher.MyEvent += m_globalSubscriber.EventProcessing;
publisher.Run();
}
}
} console
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#33
https://www.codeproject.com/Articles/29922/Weak-Events-in-C
https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/weak-event-patterns
The text was updated successfully, but these errors were encountered: