title: alternative for using slow DynamicInvoke on muticast delegate
body: <p>I have the following piece of code in a base-class:</p>
  
  <pre><code>public static void InvokeExternal(Delegate d, object param, object sender)
  {
      if (d != null)
      {
          //Check each invocation target
          foreach (Delegate dDelgate in d.GetInvocationList())
          {
              if (dDelgate.Target != null &amp;&amp; dDelgate.Target is System.ComponentModel.ISynchronizeInvoke
                  &amp;&amp; ((System.ComponentModel.ISynchronizeInvoke)(dDelgate.Target)).InvokeRequired)
              {
                  //If target is ISynchronizeInvoke and Invoke is required, invoke via ISynchronizeInvoke
                  ((System.ComponentModel.ISynchronizeInvoke)(dDelgate.Target)).Invoke(dDelgate, new object[] { sender, param });
              }
              else
              {
                  //Else invoke dynamically
                  dDelgate.DynamicInvoke(sender, param);
              }
          }
      }
  }
  </code></pre>
  
  <p>This code sample is responsible for invoking an event, represented as multicast delegate, where the invocation targets include small classes which do not care about cross-threading, but also classes which implement <code>ISynchronizeInvoke</code> and care a lot about cross-threading, like Windows Forms Controls. </p>
  
  <p>In theory, this snippet works pretty fine, no errors occur. But the <code>DynamicInvoke</code> is incredibly slow, not to say it's the current bottleneck of the application. </p>
  
  <p>So, there goes my question: Is there any way to speed up this little function without breaking the functionally to subscribe to the event directly?</p>
  
  <p>The signature of all events/delegates is <code>(object sender, EventArgs param)</code> </p>