L
Lee Crabtree
I'm a little confused about using Control.Invoke with an anonymous
method. It seems like the compiler is able to generate whatever glue
code is necessary to turn an anonymous method into a delegate type in
several situations, such as starting a thread:
Thread workerThread = new Thread(delegate { MessageBox.Show("Hello!"); });
However, trying to do the same thing with a form, as in:
Form1.Invoke(delegate { MessageBox.Show("Hello!"); });
nets an error stating that an anonymous method is not a delegate type,
and can't be converted. It's easy enough to wrap the anonymous method
in a MethodInvoker or whatever other required delegate type, but I don't
really understand why the difference exists at all.
Lee Crabtree
method. It seems like the compiler is able to generate whatever glue
code is necessary to turn an anonymous method into a delegate type in
several situations, such as starting a thread:
Thread workerThread = new Thread(delegate { MessageBox.Show("Hello!"); });
However, trying to do the same thing with a form, as in:
Form1.Invoke(delegate { MessageBox.Show("Hello!"); });
nets an error stating that an anonymous method is not a delegate type,
and can't be converted. It's easy enough to wrap the anonymous method
in a MethodInvoker or whatever other required delegate type, but I don't
really understand why the difference exists at all.
Lee Crabtree