Some notes on software development... RSS 2.0
# Friday, 15 August 2008

When trying to use anonymous methods called by Control.Invoke, like so:

this.Invoke(delegate { txtTest.Text = "Hello World"; });

you get the follow compiler error:


This is because the Delegate class, expected by the Control.Invoke method, is not a delegate type which the anonymous method is.
To work round this you can cast the anonymous method to a MethodInvoker delegate.
Our previous code now becomes:

this.Invoke((MethodInvoker)delegate { txtTest.Text = "Hello World"; });

Guy Mahieu has a nice blog about it here.

Friday, 15 August 2008 16:13:17 (GMT Standard Time, UTC+00:00)  #    -

Sign In
Total Posts: 116
This Year: 0
This Month: 0
This Week: 0
Comments: 36
About the author/Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2019
Hadrian Phillips

All Content © 2019, Hadrian Phillips
DasBlog theme 'Business' created by Christoph De Baene (delarou)