EventAggregator Latency Issue

Topics: Prism v4 - WPF 4
Jan 15, 2011 at 8:04 PM

Has anyone experienced latency issues with using the Prism v4 EventAggregator?

We're noticing inconsistent delays between the time events are published and the time the subscribers consume them.

During our latest test we fired off about 30 events (of one event type) in rapid succession, and the event subscriber showed delays of up to a few seconds between consuming the events.

Any feedback or advice is greatly appreciated.

Jan 15, 2011 at 9:24 PM
Edited Jan 15, 2011 at 9:24 PM

We use this EventAggregatorFactory:

  public static class EventAggregatorFactory
    {
        // Singleton instance of the EventAggregator service.
        private static EventAggregator _eventAggregator = null;

        // Lock (sync) object.
        private static object _syncLock = new object();

        public static EventAggregator EventAggregator
        {
            get
            {
                // Lock execution thread in case of multi-threaded access.
                lock (_syncLock)
                {
                    if (null == _eventAggregator)
                        _eventAggregator = new EventAggregator();

                    return _eventAggregator;
                }
            }
        }
    }

Jan 15, 2011 at 9:32 PM

We changed our EventAggregatorFactory to:


    public static class EventAggregatorFactory
    {
        // Singleton instance of the EventAggregator service.
        private static EventAggregator _eventAggregator = new EventAggregator();

        public static EventAggregator EventAggregator
        {
            get
            {
                return _eventAggregator;
            }
        }
    }

Same problem - after firing off many events simultaneously, the events can take up to several seconds to be consumed.

Developer
Jan 17, 2011 at 5:24 PM

Hi,

We've had no similar issues reported so far. You could try debuggin the EventBase.InternalPublish method to determine which part of the event execution process is taking more time than expected. Also, you should check whether the delay is caused by an application specific cause. Note that in order to debug the EventBase class, you should reference the Prism.Desktop project instead of the Microsoft.Practices.Prism compiled assembly. Take into account that if you make a reference to a Prism Library project instead of a compiled assembly, you should do so with any other project from the Prism Library, such as the Mef Extensions or Unity Extensions. You can read more about that in this thread.

You could also check the Event Aggregation QuickStart for more information on how the Event Aggregator works.

If you can't find the cause by doing this, it would be useful if you could provide us with a repro sample so we can help you find out where the problem is.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi