Hi,
I'm working on a WPF application with Prism.
I have a wrapper around IEventAggregator similar to the one described here: http://rachel53461.wordpress.com/2011/06/05/communication-between-viewmodels-with-mvvm/
I have a multi step process with a progress tab. As I navigate through the process, the progress bar gets populated. As I complete a step, I dispatch a message to the progress tab so that it can update progress accordingly. First way round this works fine. Once the process is complete, I close the window and send user to the home screen.
I then start the same process again and this is where the problem starts. View models subscribe to the events, however, the old subscriptions are still alive, so as I navigate through the steps, the same message gets published twice, which is a massive problem.
I use weak references as I expect Prism to dispose of old subscriptions.
If I were to unsubscribe from all the events, I would have to do this at the very end of the process (final confirmation screen). This is not feasible as final confirmation screen isn't aware of all the components (view models) that are already subscribed. I would also argue and say that it shouldn't be aware of these components as it makes the design tightly coupled.
I have tried implementing IDisposable on the view models, but it's not being called.
I have also tried implementing a destructor and then manually calling GC.Collect() - this also did nothing.
I have also read the following blog post: https://compositewpf.codeplex.com/workitem/4925 - it says that subscriptions don't get cleared unless the filter is specified. This didn't help either.
With regards to infrastructure, my event broker (wrapper around IEventAggregator) gets injected by structure map on the application startup. The same instance of the event broker is used throughout the application.
View models get injected into the window. I then set window's data context to the view model that has been injected.
I currently don't use any other feature of Prism, just the event aggregator.
I'm unable to post the project as it's very large and has many dependencies (both hardware and software). I've spent over a day on this so far and I would be most grateful for any advise/suggestions.
Thank you
I'm working on a WPF application with Prism.
I have a wrapper around IEventAggregator similar to the one described here: http://rachel53461.wordpress.com/2011/06/05/communication-between-viewmodels-with-mvvm/
I have a multi step process with a progress tab. As I navigate through the process, the progress bar gets populated. As I complete a step, I dispatch a message to the progress tab so that it can update progress accordingly. First way round this works fine. Once the process is complete, I close the window and send user to the home screen.
I then start the same process again and this is where the problem starts. View models subscribe to the events, however, the old subscriptions are still alive, so as I navigate through the steps, the same message gets published twice, which is a massive problem.
I use weak references as I expect Prism to dispose of old subscriptions.
If I were to unsubscribe from all the events, I would have to do this at the very end of the process (final confirmation screen). This is not feasible as final confirmation screen isn't aware of all the components (view models) that are already subscribed. I would also argue and say that it shouldn't be aware of these components as it makes the design tightly coupled.
I have tried implementing IDisposable on the view models, but it's not being called.
I have also tried implementing a destructor and then manually calling GC.Collect() - this also did nothing.
I have also read the following blog post: https://compositewpf.codeplex.com/workitem/4925 - it says that subscriptions don't get cleared unless the filter is specified. This didn't help either.
With regards to infrastructure, my event broker (wrapper around IEventAggregator) gets injected by structure map on the application startup. The same instance of the event broker is used throughout the application.
View models get injected into the window. I then set window's data context to the view model that has been injected.
I currently don't use any other feature of Prism, just the event aggregator.
I'm unable to post the project as it's very large and has many dependencies (both hardware and software). I've spent over a day on this so far and I would be most grateful for any advise/suggestions.
Thank you