title: WPF Dispatcher issue
body: <p>I'm attempting to update my app to use WPF instead of WinForms and have a problem I need a few pointers as I can't figure out what is wrong....</p>
  
  <p>The code below is from my Winform app which works fine</p>
  
  <pre><code>private delegate void LoginAsyncCallbackDelegate(IAsyncResult result);
  private void LoginAsyncCallback(IAsyncResult result)
  {
      if (this.InvokeRequired)
      {
          try
          {
              LoginAsyncCallbackDelegate d = new LoginAsyncCallbackDelegate(LoginAsyncCallback);
              this.Invoke(d, new object[] { result });
          }
          catch (Exception ex)
          {
              AddErrorToList(ex.ToString());
          }
      }
      else
      {
          DRVis.upx.api.global.LoginResp resp = APIWrapper.UPGlobalService.Endlogin(result);
  
          var state = (CustomAsyncStateContainer)result.AsyncState;
  
          // Session manager
          if (resp != null &amp;&amp; resp.header != null &amp;&amp; resp.header.sessionToken != null)
              SessionTokenManager.ReturnSessionToken(resp.header.sessionToken);
  
          DisplayLogin(resp, state);
      }
  }
  </code></pre>
  
  <p>The following are changes I've made in an attempt to make it work in WPF but the app crashes on the line <strong>if (!this.Dispatcher.CheckAccess())</strong></p>
  
  <pre><code>private delegate void LoginAsyncCallbackDelegate(IAsyncResult result);
  private void LoginAsyncCallback(IAsyncResult result)
  {
      if (!this.Dispatcher.CheckAccess()) //Progam Crashes here!!
      {
          try
          {
              LoginAsyncCallbackDelegate d = new LoginAsyncCallbackDelegate(LoginAsyncCallback);
              this.Dispatcher.Invoke(DispatcherPriority.Normal, d, new object[] { result });
          }
          catch (Exception ex)
          {
              AddErrorToList(ex.ToString());
          }
      }
      else
      {
          DRVis.upx.api.global.LoginResp resp = APIWrapper.UPGlobalService.Endlogin(result);
  
          var state = (CustomAsyncStateContainer)result.AsyncState;
  
          // Session manager
          if (resp != null &amp;&amp; resp.header != null &amp;&amp; resp.header.sessionToken != null)
              SessionTokenManager.ReturnSessionToken(resp.header.sessionToken);
  
          DisplayLogin(resp, state);
      }
  }
  </code></pre>
  
  <p>with stack trace....</p>
  
  <pre><code>The error time: 16/08/2012 13:06
  Exception: System.ArgumentException: Object of type 'System.Object[]' cannot be converted to type 
  
  'System.IAsyncResult'.
     at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
     at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
     at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, 
  
  CultureInfo culture, Signature sig)
     at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, 
  
  Object[] parameters, CultureInfo culture)
     at System.Delegate.DynamicInvokeImpl(Object[] args)
     at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
     at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 
  
  numArgs, Delegate catchHandler)
  </code></pre>
  
  <p>Can someone help me get the correct syntax to replace this.InvokeRequired and this.Invoke in WPF or point out something obvious I'm missing?</p>
  
  <p>Thanks
  O</p>