Skip to content

Instantly share code, notes, and snippets.

@heiswayi
Created January 31, 2021 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heiswayi/464f5e7e9ba0bda06d2d982c044e5c81 to your computer and use it in GitHub Desktop.
Save heiswayi/464f5e7e9ba0bda06d2d982c044e5c81 to your computer and use it in GitHub Desktop.
public static class DispatchService
{
public static void Invoke(Action action)
{
Dispatcher dispatchObject = Application.Current.Dispatcher;
if (dispatchObject == null || dispatchObject.CheckAccess())
{
action();
}
else
{
dispatchObject.Invoke(action);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment