繁体   English   中英

在iOS上。 当应用程序发送到后台时,该应用程序仍在同一UI线程上运行还是移至新的不同线程上?

[英]On iOS. When an app gets sent to the background, Is the app still running on the same UI thread or does it get moved to a new different thread

在iOS上。 当某个应用程序发送到后台时,该应用程序是否仍在同一UI线程上运行或是否移至新线程?

进入后台状态后,为您的应用分配的iOS线程池不会更改(当然,它们会被挂起)。

您可以通过检查NSThread.Current来查看当前正在使用的NSThread.Current

例子:

  • 如果您在DidEnterBackground查看线程,是的,它是main线程。

  • 后台获取( PerformFetch )将位于main线程上。

  • 基于后台的位置更新位于main线程上。

switch (UIApplication.SharedApplication.ApplicationState)
{
    case UIApplicationState.Background:
        Console.WriteLine($"Background location update {NSThread.Current}");
        break;
    case UIApplicationState.Active:
        Console.WriteLine($"Foreground location update {NSThread.Current}");
        break;
}

Location[16904:1947553] Foreground location update <NSThread: 0x60000006d900>{number = 1, name = main}
Location[16904:1947553] Foreground location update <NSThread: 0x60000006d900>{number = 1, name = main}
Location[16904:1947553] Foreground location update <NSThread: 0x60000006d900>{number = 1, name = main}
Location[16904:1947553] App entering background state.
Location[16904:1947553] Now receiving location updates in the background
Location[16904:1947553] Background location update <NSThread: 0x60000006d900>{number = 1, name = main}
Location[16904:1947553] Background location update <NSThread: 0x60000006d900>{number = 1, name = main}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM