How to use Anonymous methods for Control.Invoke
By Anuraj P on January 1st, 2011 . No Comments .
I previously posted about Cross-thread control access using Control.Invoke() method. But it was using Deletes. Today I tried using anonymous methods, but it wasn’t worked. Later I resolved it using Action()(or you can use MethodInvoker()) system delegate.
if (this.prgInfo.InvokeRequired)
{
this.prgInfo.Invoke(new Action(delegate()
{
//Code
}));
}
And nowadays I am working with developers, who loves to write lamda expressions every where
And this is the lamda alternative.
if (this.prgInfo.InvokeRequired)
{
this.prgInfo.Invoke(new Action(() =>
{
//Code
}));
}
You can also use the following method.
if (this.prgInfo.InvokeRequired)
{
this.prgInfo.Invoke((Action)(() =>
{
//Code
}));
}
Happy coding
No Responses to “How to use Anonymous methods for Control.Invoke”
RSS feed for comments on this post. TrackBack URL