Skip to content

Instantly share code, notes, and snippets.

@philcockfield
Created August 7, 2012 10:40
Show Gist options
  • Save philcockfield/3284433 to your computer and use it in GitHub Desktop.
Save philcockfield/3284433 to your computer and use it in GitHub Desktop.
EnsureInvokedOnMainThread
private void EnsureInvokedOnMainThread(Action action)
{
if (IsMainThread())
{
action();
return;
}
this.BeginInvokeOnMainThread(() => action());
}
private static IntPtr GetClassHandle(string clsName)
{
return (new Class(clsName)).Handle;
}
private static bool IsMainThread()
{
return Messaging.bool_objc_msgSend(GetClassHandle("NSThread"), new Selector("isMainThread").Handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment