Skip to content

Instantly share code, notes, and snippets.

@ChrisMoney
Created March 27, 2017 14:30
Show Gist options
  • Save ChrisMoney/14e392176b362a506952b98f6ec197ae to your computer and use it in GitHub Desktop.
Save ChrisMoney/14e392176b362a506952b98f6ec197ae to your computer and use it in GitHub Desktop.
Safe Invoke - Thread Safe Dispatcher.CheckAccess(), Dispatcher.Invoke and Implementation
public void DispatchIfNecessary(Action action) {
if (!Dispatcher.CheckAccess())
Dispatcher.Invoke(action);
else
action.Invoke();
}
// Invoke thread safe method
DispatchIfNecessary(() => {
methodCall();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment