Created
March 27, 2017 14:30
-
-
Save ChrisMoney/14e392176b362a506952b98f6ec197ae to your computer and use it in GitHub Desktop.
Safe Invoke - Thread Safe Dispatcher.CheckAccess(), Dispatcher.Invoke and Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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