Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot update Silverlight UI from asynchronous method completed callback
    text
    copied!<p>I have inherited some code that queries a DB over a WCF service and then employs a callback when it's done. I am trying to add some code to that callback to update the UI as the data is processed. I'm finding that I cannot get the UI to update during that callback:</p> <pre><code>client.GetDataAsync(); client.GetDataCompleted += new EventHandler&lt;GetDataCompletedEventArgs&gt;(GetDataCompleted); void GetDataCompleted(object sender, GetDataCompletedEventArgs e) { // Loop through the data // ... textBlock1.Text= "test1"; Dispatcher.BeginInvoke(() =&gt; textBlock1.Text= "test2" ); var thread = new Thread(() =&gt; { // textBlock1.Text= "test3"; (this throws a cross-thread access exception) Dispatcher.BeginInvoke(() =&gt; { textBlock1.Text= "test4"; }); } thread.Start(); // ... Debug.WriteLine("done"); } </code></pre> <p>None of these things update the UI until (apparently) the entire callback is completed. This post:</p> <p><a href="https://stackoverflow.com/questions/6264134/what-thread-calls-the-completed-event-handler-on-silverlight-wcf-calls">What thread calls the completed event handler on silverlight WCF calls?</a></p> <p>suggests that the callback is running on the main UI thread so that the BeginInvoke call should be unnecessary. Even if I add various delays in the above code, it still doesn't work. Is this possible? Is there a better way to do this?</p> <p>(This is a follow-up question to this: <a href="https://stackoverflow.com/questions/9320181/multiple-asynchronous-ui-updates-in-silverlight">Multiple asynchronous UI updates in Silverlight</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