Note that there are some explanatory texts on larger screens.

plurals
  1. POSet TextBlock from Async Completion Handler
    primarykey
    data
    text
    <p>I would like to set the text on the <code>MainPage</code> of my app, based on the response of an Async call to Web Service.</p> <p>Im getting a "The application called an interface that was marshalled for a different thread". So I know that I need to execute the</p> <pre><code>MainPage.TB_Response.text = response; </code></pre> <p>On the Primary/Main Thread, but I am unsure as to how i would go about this</p> <p>Edit: Here is my Response Handler</p> <pre><code> private void ReadResponse(IAsyncResult asyncResult) { System.Diagnostics.Debug.WriteLine("ReadResponse"); try { // The downloaded resource ends up in the variable named content. var content = new MemoryStream(); // State of request is asynchronous. //RequestState myRequestState = (RequestState)asyncResult.AsyncState; HttpWebRequest myHttpWebRequest2 = (HttpWebRequest)asyncResult.AsyncState; HttpWebResponse response = (HttpWebResponse)myHttpWebRequest2.EndGetResponse(asyncResult); //do whatever using (Stream responseStream = response.GetResponseStream()) { responseStream.CopyTo(content); byte[] data = content.ToArray(); if (data.Length &gt; 0) { string temp = System.Text.Encoding.UTF8.GetString(data, 0, data.Length); MainPage.TB_Reponse.Text = temp; System.Diagnostics.Debug.WriteLine(temp); } } } catch (WebException e) { System.Diagnostics.Debug.WriteLine(e.Message); } } </code></pre> <p>Edit2: My MainPage Class</p> <pre><code>public sealed partial class MainPage : Page { public static TextBlock TB_Reponse; public MainPage() { this.InitializeComponent(); MainPage.TB_Reponse = this.TB_Response; } protected override void OnNavigatedTo(NavigationEventArgs e) { } private void BTN_Login_Click(object sender, RoutedEventArgs e) { ... } } </code></pre>
    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.
 

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