F
Franklin
Suppose we have an object that is raising events - some class that we write
that has an event to which other objects in the app can register. I have
read that when a .NET event publisher is disposed, all subscribers are
automatically unregistered.
But I have also read that if subscribers are not explicitly unregistered,
then the GC won't collect the publisher - and the publisher will remain in
memory and even possibly continue to raise events.
So I wrote a small console app to test this. But I got hung up on the part
of the little console app that is supposed to "kill" or "destroy" or somehow
cause the event publisher to be disposed. But I don't know how to do that.
Setting a reference variable to the publisher to null obviously won't get
the job done. So, how can I "kill" or "destroy" the event publisher?
FWIW: I ultimatelyl want to be have a little demo app that proves one point
or another - that the subscribers are automatically unregistered from the
publisher when the publisher is disposed; or have it show that the publisher
cannot be disposed while it has any subscribers to one of its events. I
think I have the demo app ready to go, except I don't know how to make .NET
dispose [or attempt to dispose] of the publisher.
Thanks.
that has an event to which other objects in the app can register. I have
read that when a .NET event publisher is disposed, all subscribers are
automatically unregistered.
But I have also read that if subscribers are not explicitly unregistered,
then the GC won't collect the publisher - and the publisher will remain in
memory and even possibly continue to raise events.
So I wrote a small console app to test this. But I got hung up on the part
of the little console app that is supposed to "kill" or "destroy" or somehow
cause the event publisher to be disposed. But I don't know how to do that.
Setting a reference variable to the publisher to null obviously won't get
the job done. So, how can I "kill" or "destroy" the event publisher?
FWIW: I ultimatelyl want to be have a little demo app that proves one point
or another - that the subscribers are automatically unregistered from the
publisher when the publisher is disposed; or have it show that the publisher
cannot be disposed while it has any subscribers to one of its events. I
think I have the demo app ready to go, except I don't know how to make .NET
dispose [or attempt to dispose] of the publisher.
Thanks.