Synchronous Task with Event Aggregator

Topics: Getting Started
Feb 7, 2012 at 3:00 PM
Edited Feb 7, 2012 at 3:23 PM


In my WPF application I have a save method implemented in my current VM (say VMA) where VMA needs to get some value from other view model (say VMB), before saving. I use EventAggregator from VMA to get the values and handle the event in VMB. The VMB then issues another event with requested values and handle that event in VMA. However I dont want to execute the remaining code in SaveMethod till VMA gets back these requested values. How do I do this? Should I be using couroutines/IResult? Here is how I have it currently:

 public void SavePlan(bool saveActivity = false)       {           



               //publish event to get values
                Events.Publish(new GetFeatureGeometryAsWKTEvent(   featureId:this.AccomplishmentId.Value        ));                               

//save the shape               

 some code //want to execute it only after this VM gets back requested values               



catch (Exception ex)           



Any help is highly appreciated!!




Feb 7, 2012 at 5:10 PM

It sounds like you are describing a request/response scenario. The event aggregator is not necessarily designed with that as the primary use case. However, you could get the same result by splitting your method into two methods. The first method would publish the event. The second method would Handle the response event.

Feb 7, 2012 at 5:39 PM

Yeah agree..thanks! Appreciate your help!