Check whether or not the current thread is the main thread

前端 未结 13 968
北恋
北恋 2020-12-02 11:42

Is there any way to check whether or not the current thread is the main thread in Objective-C?

I want to do something like this.

  - (void)someMethod         


        
相关标签:
13条回答
  • 2020-12-02 12:30

    For Monotouch / Xamarin iOS you can perform the check in this way:

    if (NSThread.Current.IsMainThread)
    {
        DoSomething();
    }
    else
    {
        BeginInvokeOnMainThread(() => DoSomething());
    }
    
    0 讨论(0)
提交回复
热议问题