title: Threading issue with Dispatcher.invoke in WinRT
body: <p>I posted a question some time ago on <a href="http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/0f787059-7695-4666-a69d-41fcc41c10d2" rel="nofollow noreferrer">MSDN forum</a> involving the following code. It creates on a new thread, reads thumbnail from a file and displays it through Dispatcher.</p>
  <pre><code>private void Button_Click_1(object sender, RoutedEventArgs e)
      {
          Task.Factory.StartNew(async()=&gt;{
              var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; ;
  
              var file = await localFolder.CreateFileAsync(&quot;.txt&quot;, Windows.Storage.CreationCollisionOption.OpenIfExists);
              var t = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.DocumentsView);
              //Some proccessing....
              this.Dispatcher.Invoke(Windows.UI.Core.CoreDispatcherPriority.Normal,(a,b)=&gt;{
                  var bmp = new BitmapImage();
                  bmp.SetSource(t); //Exception here
                  image.Source = bmp;
              }, this, null);
              //Some more stuff...
          });
      }
  </code></pre>
  <p><em>image</em> is just an Image control in the XAML</p>
  <p>I get a big exception if above code executes. The exception occurs at <code>bmp.SetSource(t)</code>.</p>
  <p>Here is full exception info:</p>
  <blockquote>
  <p>Transition into COM context 0x1347668 for this RuntimeCallableWrapper
  failed with the following error: An outgoing call cannot be made since
  the application is dispatching an input-synchronous call. (Exception
  from HRESULT: 0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL)). This is
  typically because the COM context 0x1347668 where this
  RuntimeCallableWrapper was created has been disconnected or it is busy
  doing something else and cannot process the context transition. No
  proxy will be used to service the request on the COM component and
  calls will be made to the COM component directly. This may cause
  corruption or data loss. To avoid this problem, please ensure that all
  COM contexts/apartments/threads stay alive and are available for
  context transition, until the application is completely done with the
  RuntimeCallableWrappers that represents COM components that live
  inside them.</p>
  </blockquote>
  <p>Switching from using Invoke to InvokeAsync fixes the problem, but I'm wondering why. Can someone explain?</p>
  <p>EDIT: Above is just some test code. The Task I created is meant to simulate execution under a non-UI thread context which occurs in my app since it need to both read files and update UI from a none-UI thread context.</p>