In a WPF app that I\'m writing using the MVVM pattern, I have a background process that doing it\'s thing, but need to get status updates from it out to the UI.
I\'m
I handle the BackgroundWorker.ReportProgress
event outside of my ViewModel
and pass the actual BackgroundWorker
instance and the ViewModel
into my class which defines the async
method(s).
The async
method then calls bgWorker.ReportProgress
and passes a class which wraps a delegate as the UserState
(as object
). The delegate I write as an anonymous method.
In the event handler, I cast it from object
back to the wrapper type and then invoke the delegate inside.
All this means that I can code UI changes directly from the code that's running asynchronously, but it just has this wrapping around it.
This explains it in more detail:
http://lukepuplett.blogspot.com/2009/05/updating-ui-from-asynchronous-ops.html