MonoMac.Foundation.NSObject.InvokeOnMainThread C# (CSharp) Method

InvokeOnMainThread() public method

public InvokeOnMainThread ( NSAction action ) : void
action NSAction
return void
		public void InvokeOnMainThread (NSAction action)
		{
			var d = new NSActionDispatcher (action);
			Messaging.void_objc_msgSend_intptr_intptr_bool (d.Handle, selPerformSelectorOnMainThreadWithObjectWaitUntilDone, 
					NSActionDispatcher.Selector.Handle, d.Handle, true);
			GC.KeepAlive (d);
		}

Same methods

NSObject::InvokeOnMainThread ( Selector sel, NSObject obj ) : void
NSObject::InvokeOnMainThread ( Selector sel, NSObject obj, bool wait ) : void

Usage Example

		void LoadAssetsWorkerThread ()
		{

#if MACOS || IOS			
			// Create an Autorelease Pool or we will leak objects.
			using (var pool = new NSAutoreleasePool()) {
#else				
				
#endif				
				// Make sure we invoke this on the Main Thread or OpenGL will throw an error
#if MACOS
				MonoMac.AppKit.NSApplication.SharedApplication.BeginInvokeOnMainThread (delegate {
#endif
#if IOS
				var invokeOnMainThredObj = new NSObject();
				invokeOnMainThredObj.InvokeOnMainThread(delegate {
#endif
					gameplayScreen.LoadAssets ();
#if MACOS || IOS						
				});
					
			}				
#endif				

		}