Forum Xamarin.Mac

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

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.