Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jaydeepkarena/c4746350da843c5250bf1fa03af9e241 to your computer and use it in GitHub Desktop.
Save jaydeepkarena/c4746350da843c5250bf1fa03af9e241 to your computer and use it in GitHub Desktop.
C# Extension Method - InvokeIfRequired - use while updating control from different thread
public static void InvokeIfRequired<T>(this T control, Action<T> action) where T : Control
{
if (control.InvokeRequired)
{
control.Invoke(new Action(() => action(control)));
}
else
{
action(control);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment