title: Implicitly convert method group to Delegate (for argument of Control.Invoke)
body: <p>I'm working on a Windows Forms application, and it contains custom controls with methods that can potentially be called from threads other than the UI thread. So these methods therefore look a bit like this to prevent exceptions:</p>
  
  <pre><code>public void DoSomeStuff()
  {
      if (InvokeRequired)
      {
          Invoke((Action)DoSomeStuff);
      }
      else
      {
          // Actually do some stuff.
      }
  }
  </code></pre>
  
  <p>The explicit cast of the method group <code>DoSomeStuff</code> to an <code>Action</code> caught my attention, and so I've been looking into delegates and other related subjects more deeply than I have before.</p>
  
  <p>Although I've seen some related questions here, I haven't been able to find exactly the answer to mine, which is:</p>
  
  <p><strong>Why does the method group <code>DoSomeStuff</code> require explicit casting to an <code>Action</code> in this case?</strong></p>
  
  <p>If I remove the cast, then I get two errors:</p>
  
  <blockquote>
    <p>Error 102 Argument 1: cannot convert from 'method group' to
    'System.Delegate'</p>
    
    <p>Error 101 The best overloaded method match for
    'System.Windows.Forms.Control.Invoke(System.Delegate, params
    object[])' has some invalid arguments</p>
  </blockquote>
  
  <p>The fact that the compiler is apparently confused about which overload of <code>Invoke</code> to use seems like a pretty big hint, but I'm still not sure about why exactly it can't figure that out. I would expect the compiler to deduce that the first overload of <code>Invoke</code>, which takes a single <code>Delegate</code> argument, is the one that should be used.</p>
  
  <p>I would expect that because there is no problem if the code is written like this:</p>
  
  <pre><code>Action a = DoSomeStuff;
  Invoke(a);
  </code></pre>
  
  <p>The method group <code>DoSomeStuff</code> can be implicitly converted to the <code>Action</code> delegate type, and <code>Action</code> derives (technically?) from <code>System.Delegate</code>, so <code>Invoke</code> can handle the argument <code>a</code> without any trouble. But then why can't the implicit conversion be done by the compiler when I try to pass <code>DoSomeStuff</code> as the argument directly? To be honest I'm not convinced by my own logic here, but I still am not sure what I'm missing.</p>