Forum Xamarin.Mac

Access Main Thread

PhilipJohnPhilipJohn USMember ✭✭✭

Simple question. How do I access the main thread from a background thread in Xamarin.Mac? In Xamarin.iOS I use

InvokeOnMainThread(() => {
//do something
});

and while InvokeOnMainThread is a method of NSObject, it doesn't appear to exist in Xamarin.Mac.

I'm using Task.Run to create the background thread.

Best Answer

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    Accepted Answer

    InvokeOnMainThread does exist in Xamarin.Mac, double check the object you are trying to call it on.

    NSApplication.SharedApplication is a global NSObject you can fetch to invoke/begininvoke on

Answers

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    Accepted Answer

    InvokeOnMainThread does exist in Xamarin.Mac, double check the object you are trying to call it on.

    NSApplication.SharedApplication is a global NSObject you can fetch to invoke/begininvoke on

Sign In or Register to comment.