title: Sending Image from WPF to Web API, thread error
body: <p>So, I want to send the image from my WPF app to the Web API controller. When I get the image as BitmapImage and try to send it, I get the error "the calling thread cannot access this object because a different thread owns it". I don't see how am I modifying UI and why do I get the error. Here's the code:</p>
  
  <p>WPF code:</p>
  
  <pre><code>private void BtnSendImage_Click(object sender, RoutedEventArgs e)
      {
          OpenFileDialog ofd = new OpenFileDialog();
          ofd.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString();
          BitmapImage slika = null;
  
          if (ofd.ShowDialog() == true)
          {
              odabranaSlika = ofd.FileName;
              Uri adresa = new Uri(odabranaSlika, UriKind.Absolute);
              slika = new BitmapImage(adresa);
              ItemDAL idal = new ItemDAL();
  
              if (idal.SendImage(slika))
              {
                  MessageBox.Show("Yay!");
              }
              else
              {
                  MessageBox.Show("Awwww");
              }
          }
      }
  </code></pre>
  
  <p>Method SendImage from the ItemDAL class (the code stops at postResult.Wait() part):</p>
  
  <pre><code>public bool SendImage(BitmapImage bmp)
      {
          using (var client = new HttpClient())
          {
              client.BaseAddress = new Uri("http://localhost:52407/");
              var postResult = client.PostAsJsonAsync&lt;BitmapImage&gt;("api/values/postimage", bmp);
              postResult.Wait();
  
              var result = postResult.Result;
              if (result.IsSuccessStatusCode)
              {
                  return true;
              }
              else
              {
                  return false;
              }
          }
      }
  </code></pre>
  
  <p>What am I doing wrong? I know I'm not suppose to modify UI, unless it's from the main thread, bot how is this doing anything to the UI?</p>