Awesome - thanks *Rolf*.
On Tue, Aug 7, 2012 at 10:56 PM, Rolf Bjarne Kvinge <[email protected]>wrote: > Hi, > > There are likely more efficient ways to this. > > One way would be to have a [ThreadStatic] variable which you set to true > in your Main method. That way it'll only be true for the main thread. > > The only way to really tell what is faster though is to actually measure > the difference (and do you actually know that this code is called a lot in > your app? If not, it won't be a problem. Have in mind that anything > UI-related will likely drown this piece of code completely). > > Best regards, > Rolf > > On Tue, Aug 7, 2012 at 12:43 PM, Phil Cockfield <[email protected]>wrote: > >> I've got some same code which is designed to make sure an Action is >> invoked on the UI thread. >> Here it is here: >> >> https://gist.github.com/3284433 >> >> It uses this to determine if it's running on the UI thread. Is code the >> most efficient way to do this? It seems a bit baroque to be marshalling >> out over a *bool_objc_msgSend *type method. >> >> >> private static bool IsMainThread() >> >> { >> >> return Messaging.bool_objc_msgSend(GetClassHandle("NSThread"), >> newSelector( >> "isMainThread").Handle); >> >> } >> >> >> Thanks! >> >> -- >> *Phil *Cockfield >> >> >> >> >> _______________________________________________ >> MonoTouch mailing list >> [email protected] >> http://lists.ximian.com/mailman/listinfo/monotouch >> >> > -- *Phil *Cockfield
_______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
