Control.Invoke Gotcha

October 25th, 2005

I recently stumbled (of course) across an interesting wrinkle in Control.Invoke/BeginInvoke. From the fine print:

The [invoked] delegate can be an instance of EventHandler, in which case the sender parameter will contain this control, and the event parameter will contain EventArgs.Empty.

I dunno… While this seems to be done in order to preserve the notion of “sender” in an eventhandler, this strikes me as a somewhat shady clause to Invoke’s contract.

One Response to “Control.Invoke Gotcha”

  1. Daniel Chait Says:

    Fancy! I also saw in the docs you pointed to:

    A call to an EventHandler or MethodInvoker delegate will be faster than a call to another type of delegate.

    Hmm. Seems like for any other delegate type they will do a DynamicInvoke but that they’ve optimized here for these two “special” delegate types. WinForms performance mavens, take heed.