Tired of all Invoke methods? Use this Invoke + Lambda
Here is an tiny example of an practical Extension method that will save you a ton of time working with Windows Forms with multiple Threads, it should be possible to easily port this one for WPF if you use that.
public static class ControlExtensions
{
public static void SuperInvoke(this Control control, Action action)
{
if (control.InvokeRequired)
control.Invoke(action);
else
action();
}
}
To use this extension method it's pretty simple, Inside your form somewhere example if you want to update example an textbox with some text.
this.SuperInvoke(() => txtMax.Text = "New text Line" );
Hope this will help some in the future or speed up coding for projects that you don't want to waste to much time with.
Fork
1 Feedback
You must log in before you can give any feedback
You must log in before you can post a comment


552
1




Mark '.net' tag as 'like'
Mark '.net' tag as 'ignore'