Could anyone help me i have a problem I\'m trying to get this code to work in the background via threadpool but i cannot seem to get it to work i keep getting this error:
This extension method solves the problem too.
///
/// Allows thread safe updates of UI components
///
public static void InvokeEx(this T @this, Action action) where T : ISynchronizeInvoke
{
if (@this.InvokeRequired)
{
@this.Invoke(action, new object[] { @this });
}
else
{
action(@this);
}
}
Use in your worker thread as follows
InvokeEx(x => x.MyControl.Text = "foo");