title: Invoking WPF Dispatcher with anonymous method
body: <p>I just realized in a C# .Net 4.0 WPF background thread that this doesn't work (compiler error):</p>
  
  <pre><code>Dispatcher.Invoke(DispatcherPriority.Normal, delegate()
  {
      // do stuff to UI
  });
  </code></pre>
  
  <p>From some examples I found out that it had to be casted like this: <code>(Action)delegate()</code>. However, in other examples it is casted to other classes, e.g. <code>System.Windows.Forms.MethodInvoker</code>.</p>
  
  <p>Can anybody tell me what exactly is wrong with the example above? I also tried to reproduce it with other methods, but it was always working without casting:</p>
  
  <pre><code>delegate void MyAction();
  void Method1(MyAction a) {
      // do stuff
  }
  
  void Method2(Action a) {
      // do stuff
  }
  
  void Tests()
  {
      Method1(delegate()
      {
          // works
      });
  
      Method2(delegate()
      {
          // works
      });
  
      Method1(() =&gt;
      { 
          // works
      });
  
      Method2(() =&gt;
      {
          // works
      });
  
      Method2(new Action(delegate()
      {
          // works
      }));
  
      new System.Threading.Thread(delegate()
      {
          // works
      }).Start();
  }
  </code></pre>
  
  <p>So whats the best (most elegant, less redundant) way to invoke the Dispatcher, and whats so special with it that delegates must be casted?</p>