How to properly notify UI about fast changing data?

Topics: Prism v2 - WPF 3.5
Jan 6, 2010 at 8:22 PM

Hi all,

I am attempting to use the CompositeWPF library in my new desktop application but I am faced with an issue of which I cannot determine the best practice.

I have a third party library which processes some GPS data and provides me with a single object I can use containing a whole set of properties and an update function. I should call this update function so many times (the goal is between 20 and 50 times per second) to retrieve and process new data. For that I created a seperate helper library which performs all the low level tasks.

public class Manager
  public void UpdateLoopFromBackgroundThread()

Every time the update function is called about 20 properties from the third party library get updated.

Now I have 7 modules which should use the data from this third party library so each of them can draw different plots which are of course also update between 2 and 10 times per second. What's the best way to notify these modules they should redraw their plot? I can't use change notifiers on the ThirdPartyLib object because the object itself doesn't change, and as far as I can tell putting those notifier events on each individual property is also not desired. I also don't like to create a custom class which has the same properties as the ThirdPartyLib object and create a new one 50 times per second, that might be too hard for the Garbage Collector.

I was thinking of putting a timer in my module which is triggered every 500 or 100 milliseconds and to use the properties from the ThirdPartyLib object to update my views. I also considered using an event in the UpdateLoopFromBackgroundThread() function on which my modules can add an event handler but I think that's not a correct use of the mvvm pattern, plus all those event calls might be quite expensive performance wise.

Any pointers on a correct solution are greatly appreciated. All the samples I encountered only processed relative static data so any articles or samples are always welcome.

Jan 7, 2010 at 11:44 AM

as an interesting approach, you might want to take a look at Rx.

and this post

Other than that, using the event aggregator to publish the events might be an option.  Have the modules/views subscribe to the events they need.  But make sure that you read


Jan 7, 2010 at 11:47 AM
Edited Jan 7, 2010 at 12:09 PM

some more interesting links about Rx

This is available for 3.5 from the first link I gave above ( ). 

If you go this path, I would be very interested in hearing about the results.  The interesting part would be the surfacing of the feed to the dynamically loaded modules.  I would think that the use of the Unity Container would play a large role here. Registering the appropriate services in the container and then being able to receive the data through Rx.  You might also want to ask the same question on the Rx Forum and see if they have any suggestions


Jan 7, 2010 at 1:33 PM

I agree with Paul that Rx would be a good candidate to solve your problem.

Another (maybe simpler) approach would be to put a .NET event on your Manager class that gets raised every time the GPS data is updated. You can then register a singleton instance of the manager class in the container and get a reference to it whereever you need to have your data/views refreshed. Once you have the reference, you can hook into the event to update your views.

This is a similar approach to what Paul suggested with the Event Aggregator, but I think it would perform slightly better - especially since you'll be updating the data so frequently.

Hope that helps.


Jan 7, 2010 at 5:18 PM

Thanks for the replies.

I think that I don't have the time to look up and check the Rx framework.

As for the events, I feel like that would cause a lot of overhead because an event feels like a very expensive call. I also don't know if that's the proper way to handle this. Right now I am working with a timer in my module controller which run at a lower rate than my main update loop which fetch the date using a service and update the properties in my viewmodel class. I am not sure this is a better way, but it feels less expensive and the benefit is that my modules don't necessarily have to be in sync or one module is delayed while another's event handler is still computing.