在iOS上。当应用程序被发送到后台时,该应用程序是仍然在同一UI线程上运行,还是被移到新的线程上?
发布于 2018-01-30 12:57:30
在进入后台状态时,你的应用程序的iOS分配线程池不会改变(当然它们会被挂起)。
您可以通过检查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}
https://stackoverflow.com/questions/48521192
复制相似问题