Events Stop Being Caught after some time...

Sep 12, 2008 at 10:35 AM
Hi there,

Here I am one again to ask for help. :p

The problem now is that I'm using the EventAggregator to publish and subscribe some events to send information between some of my modules.

The problem is that, for some reason, the events stop working after some period without any exception or problem... They simply stop working, by this I mean that my subscribers after some time don't capture the events fired, the number of events captured are not always equal, in a execution in can only capture 1 event and in the next it can be caught several events. I've tried everything I recall but without success.

The code I use to publish an event is:

MenuClickParams Eparams = new MenuClickParams();
Eparams.ClickButtonDescription = "CreateEvent";
ConfiguratorContainer.EAggregator.GetEvent<MenuClickEvent>().Publish(Eparams);


The code I use to subscribe to a event is:

MenuClickEvent CreateEventEvent = ConfiguratorContainer.EAggregator.GetEvent<MenuClickEvent>();
CreateEventEvent.Subscribe(CreateEventEventHandler, ThreadOption.PublisherThread, false, e => e.ClickButtonDescription == "CreateEvent");



The MenuClickEvent Class is defined by:

public class MenuClickEvent : CompositeWpfEvent<MenuClickParams>{}


And the MenuClickParams is defined by:

    public class MenuClickParams
    {
        private string clickButtonDescription;

        public string ClickButtonDescription
        {
            get { return clickButtonDescription; }
            set { clickButtonDescription = value; }
        }

    }


Any ideas of what I'm doing wrong? Or how can I solve this?

Thanks in advance,
Regards,
Daniel Alves

Sep 12, 2008 at 12:52 PM
Edited Sep 12, 2008 at 12:53 PM
Daniel,

It sounds to me as though your subscribers are being garbage collected. To verify, try changing the false in your Subscribe call to true. If the problem goes away, it's a GC issue and you'll want to consider what should be holding a reference to your subscriber (or whether you'd prefer to manually unsubscribe rather than having a weak reference between the event aggregator and your subscriber).

HTH,
Kent
Sep 12, 2008 at 1:32 PM
Hi there Kent...

Thanks for your answer... That solved my problem... I am unsubscribing the events manually... now...

Thanks again,
Daniel Alves