Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Silverlight uses a queue of work items to handle rendering and logic on the UI thread. Since your logic also runs on the UI thread (in your <code>button_Click</code> handler) the renderer doesn't get a chance to draw the screen until your method is done executing AND the internal message loop gets around to drawing the screen. </p> <p>Your <code>BeginInvoke</code> immediately places your function on the Silverlight work queue to execute on the UI thread (and returns immediately). The order Silverlight processes this is probably something like:</p> <ul> <li>User clicks the button, placing a click event on the work queue</li> <li>Silverlight sees the click event and calls <code>button_Click</code> (which places a new action on the work queue)</li> <li>Process the next work queue item which is probably your <code>Thread.Sleep</code> action, pausing the UI thread for 5 seconds</li> <li>Finally Silverlight gets around to painting the screen</li> </ul> <p>What you want to do is start a new thread to do your work, then <code>BeginInvoke</code> <em>back</em> to the UI thread:</p> <pre><code>var thread = new Thread(() =&gt; { Thread.Sleep(5000); Dispatcher.BeginInvoke(() =&gt; { // update UI textBox.Text = "2"; }); }); textBox.Text = "1"; thread.Start(); </code></pre> <p>I should add that Silverlight 5 adds a composition thread that can perform certain actions to update the UI without blocking the UI thread like playing animations and doing GPU accelerated rendering where possible.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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