title: Trying to update image control source from other tread and getting Error
body: <p>My project is about capturing the full screen and updating the image control by this images;</p>
  
  <p>At the last line (<code>image1.Source = img;</code>) I get the error:</p>
  
  <pre><code>The calling thread cannot access this object because a different thread owns it.
  </code></pre>
  
  <p>the code:</p>
  
  <pre><code>public partial class MainWindow : Window
  {
  
      delegate void  MyDel(BitmapImage img);
  
      Queue&lt;BitmapImage&gt; picQueue = new Queue&lt;BitmapImage&gt;();
  
      public MainWindow()
      {
          InitializeComponent();
  
          Thread updateTrd = new Thread(new ThreadStart(UpdateQueue));
          updateTrd.Start();
  
          Thread PicTrd = new Thread(new ThreadStart(UpdateScreen));
          PicTrd.Start();
      }
  
      private void UpdateQueue()
      {
          while (true)
          {
              ScreenCapture sc = new ScreenCapture();//this function provide a desktop screenshot
              System.Drawing.Image img = sc.CaptureScreen();
              Stream stream = new MemoryStream();
              img.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
  
              BitmapImage image = new BitmapImage();
              image.BeginInit();
              image.StreamSource = stream;
              image.EndInit();
  
              picQueue.Enqueue(image);
          }
      }
  
      private void UpdateScreen()
      {
          while (true)
          {
              if (picQueue.Count &gt; 0)
              {
                  SwitchPic(picQueue.Dequeue());
              }
              else
              {
                  Thread.Sleep(30);
              }
          }
      }
  
      private void SwitchPic(BitmapImage img)
      {
          if(!image1.Dispatcher.CheckAccess())
          {
              this.image1.Dispatcher.BeginInvoke(new MyDel(SwitchPic), img);
          }
          else
          {
              image1.Source = img;
          }
      }
  }
  </code></pre>