Jonathon Rossi

My little bit of the internet.

Calling Control.Invoke() with anonymous methods

With the help of a blog post by Jeremy D. Miller and a comment from Geert Baeyaert, I am now using anonymous methods with Control.Invoke(). This code sure beats writing delegates for every control you want to make changes to.

The basic code is as follows, which can be improved to check Control.InvokeRequired to improve performance:

Invoke((MethodInvoker)delegate {
    // Code to access WinForms controls here