Note that there are some explanatory texts on larger screens.

plurals
  1. POUI Thread/Dispatcher Issue (BeginInvoke)
    primarykey
    data
    text
    <p>In a previous question I asked how to get access to UI elements in a callback thread. I got a lot of good answers, one of which was to implement a wrapper class such as this:</p> <pre><code>public static class UIThread { private static readonly Dispatcher Dispatcher; static UIThread() { Dispatcher = Deployment.Current.Dispatcher; } public static void Invoke(Action action) { if (Dispatcher.CheckAccess()) { action.Invoke(); } else { Dispatcher.BeginInvoke(action); } } } </code></pre> <p>And you can call this using</p> <pre><code>UIThread.Invoke(() =&gt; TwitterPost.Text = "hello there"); </code></pre> <p>However I tried extending this by calling the following in my callback function</p> <pre><code>UIThread.Invoke(() =&gt; loadUserController(jsonObject)); </code></pre> <p>with the following method:</p> <pre><code>private void loadUserController(JObject jsonObject) { string profile_image_url = (string)jsonObject["profile_image_url"]; string screen_name = (string)jsonObject["screen_name"]; string name = (string)jsonObject["name"]; string location = (string)jsonObject["location"]; int statuses_count = (int)jsonObject["statuses_count"]; if (!string.IsNullOrEmpty(profile_image_url)) { ProfileImage.Source = new BitmapImage(new Uri("blahblahbalhb.jpg", UriKind.Absolute)); } // Set the screen name and display name if it differs if (!string.IsNullOrEmpty(name) &amp;&amp; !string.IsNullOrEmpty(screen_name)) { ScreenName.Text = screen_name; if (!screen_name.Equals(name)) { _Name.Text = name; } } if (!string.IsNullOrEmpty(location)) { Location.Text = location; } Tweets.Text = statuses_count.ToString() + " Tweets"; } </code></pre> <p>then the image will not render until another action forces a redraw (clicking a button) but the text controls will be updated. If within my callback function I call setImageFile(string imageFile) which is implemented as:</p> <pre><code>private void setImageFile(string imageFile) { if (this.Dispatcher.CheckAccess()) { ProfileImage.Source = new BitmapImage(new Uri("fdsfdfdsf.jpg", UriKind.Absolute)); } else { this.Dispatcher.BeginInvoke(new Action&lt;string&gt;(setImageFile), imageFile); } } </code></pre> <p>then the image will be rendered immediately. Why is this happening? What properties of the Dispatcher am I not fully understanding?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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