Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had a similar scenario just this week (MVVM here too). I had a separate class doing its thing, reporting back status on an event handler. The event handler <i>was being called as expected, and I could see the results coming back right on time with Debug.WriteLine's</i>.</p> <p>But with WPF, no matter what I did, the UI would not update until the process was complete. As soon as the process finished, the UI would update as expected. It was as if it was getting PropertyChanged, but waiting for the thread to complete before doing the UI updates all at once. </p> <p>(Much to my dismay, the same code in Windows.Forms with a DoEvents and .Refresh() worked like a charm.)</p> <p>So far, I've resolved this by starting the process on its own thread:</p> <pre><code>//hook up event handler myProcess.MyEvent += new EventHandler&lt;MyEventArgs&gt;(MyEventHandler); //start it on a thread ... ThreadStart threadStart = new ThreadStart(myProcess.Start); Thread thread = new Thread(threadStart); thread.Start(); </code></pre> <p>and then in the event handler:</p> <pre><code>private void MyEventHandler(object sender, MyEventArgs e) { .... Application.Current.Dispatcher.Invoke( DispatcherPriority.Send, (DispatcherOperationCallback)(arg =&gt; { //do UI updating here ... }), null); </code></pre> <p>I'm not recommending this code, since I'm still trying to understand the WPF thread model, how Dispatcher works, and why in my case the UI wouldn't update until the process was complete even with event handler getting called as expected (by design?). But this has worked for me so far.</p> <p>I found these two links helpful:</p> <p><a href="http://www.nbdtech.com/blog/archive/2007/08/01/Passing-Wpf-Objects-Between-Threads-With-Source-Code.aspx" rel="nofollow noreferrer">http://www.nbdtech.com/blog/archive/2007/08/01/Passing-Wpf-Objects-Between-Threads-With-Source-Code.aspx</a></p> <p><a href="http://srtsolutions.com/blogs/mikewoelmer/archive/2009/04/17/dealing-with-unhandled-exceptions-in-wpf.aspx" rel="nofollow noreferrer">http://srtsolutions.com/blogs/mikewoelmer/archive/2009/04/17/dealing-with-unhandled-exceptions-in-wpf.aspx</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload