title: UnauthorizedAccessException: Invalid cross-thread access in Silverlight application (XAML/C#)
body: <p>Relatively new to C# and wanted to try playing around with some third party web service API's with it.</p>
  
  <p>Here is the XAML code</p>
  
  <pre><code>    &lt;Grid x:Name="ContentGrid" Grid.Row="1"&gt;
          &lt;StackPanel&gt;
              &lt;Button Content="Load Data" Click="Button_Click" /&gt;
              &lt;TextBlock x:Name="TwitterPost" Text="Here I am"/&gt;
          &lt;/StackPanel&gt;
      &lt;/Grid&gt;
  </code></pre>
  
  <p>and here is the C# code</p>
  
  <pre><code>    private void Button_Click(object sender, RoutedEventArgs e)
      {
          HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://api.twitter.com/1/users/show/keykoo.xml");
          request.Method = "GET";
  
          request.BeginGetResponse(new AsyncCallback(twitterCallback), request);
      }
  
      private void twitterCallback(IAsyncResult result)
      {
          HttpWebRequest request = (HttpWebRequest)result.AsyncState;
          HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
          TextReader reader = new StreamReader(response.GetResponseStream());
          string strResponse = reader.ReadToEnd();
  
          Console.WriteLine("I am done here");
          TwitterPost.Text = "hello there";
      }
  </code></pre>
  
  <p>I'm guessing that this is caused by the fact that the callback executes on a separate thread than the UI?  What is the normal flow to deal with these types of interactions in C#?</p>
  
  <p>Thanks.</p>