I have to be slowed down with the search, because here is another seemingly common problem that I could not solve.
Here is my problem - I use WPF and MVVM, and I have a statemachine that runs in the model. If an error occurs, I need to pass the information to the ViewModel in order to display this error. This part seems to be working fine. When the user clicks the desired behavior, the code in the model continues and looks at the object with which the user interacts to determine what to do next.
The problem is that the model needs to reload the file, which updates the GUI with the contents of the specified file. Since the model runs in a thread, you can imagine what I will ask next - how the hell did you synchronize correctly with the GUI? In MFC, I would use SendMessage or PostMessage to perform GUI updates.
I read articles for WinForms that suggest using InvokeRequired to automatically call BeginInvoke if necessary. I really did not know that BeginInvoke would do what I wanted, so I was asked to study this.
How can I call BeginInvoke from my model? Does this method even apply to WPF? . I went ahead and implemented the delegate and then called Invoke, but I get the same error that tells me that the collection cannot be modified from this thread. I also tried BeginInvoke, damn it, but I guess that won't work either, because it will still start from another thread.
Confused If I missed something really obvious that was published all over the Internet, go ahead and give me a verbal overlay, I probably deserve it.
EDIT . I should probably add that I'm looking for something else besides a timer or a BackgroundWorker based solution, if that is the only way to solve this problem in WPF / MVVM. Also, I am wondering if any of the MVVM toolkits can have such features ...
synchronization user-interface c # wpf mvvm
Dave Mar 09 '10 at 17:34 2010-03-09 17:34
source share