简体   繁体   English

如何在运行时测试当前是否在主队列上执行了块?

[英]How to test at runtime if a block is currently executed on the main queue?

I am using an API where it is not entirely clear if the block is always executed on the main queue. 我使用的API尚不清楚,该块是否总是在主队列上执行。 If it is not, then I need to call the main queue synchronously. 如果不是,那么我需要同步调用主队列。

How can I check if the block is already executing on the main queue? 如何检查该块是否已在主队列上执行? dispatch_get_current_queue() is deprecated. dispatch_get_current_queue()已弃用。 Must I use dispatch_get_specific() to get an comparable identifier? 我是否必须使用dispatch_get_specific()获得可比较的标识符?

The unique thing about the main queue is that it is always matched exactly to the main thread. 关于主队列的独特之处在于,它始终与主线程完全匹配。 So you can use [NSThread isMainThread] . 因此,您可以使用[NSThread isMainThread]

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

相关问题 如何让CATiledLayer不阻塞主线程 - How to have CATiledLayer not block the main thread 完成块执行后如何从函数返回字符串? - How to return string from function after completion block executed? iPhone 开发 - 我如何在运行时找出 UITableView 中当前显示的顶部单元格是什么? - iPhone dev - How can I find out at runtime what the top cell that's currently being displayed is in a UITableView? 执行块后,在块中执行一段代码 - Execute a piece of code in block after the block is executed 使用addOperationWithBlock将块添加到队列并使用完成块 - Add block to queue with addOperationWithBlock and use completion block 为什么在主队列上调用dispatch_sync()会阻塞主队列? - Why dispatch_sync( ) call on main queue is blocking the main queue? UIAlertView在主队列上崩溃。 - UIAlertView on main queue crashing. 使块在串行队列中等待 - Making a block wait in a serial queue 如何在ios中进行函数调用等待,直到该函数内的块完全执行? - How to make a function call in ios to wait, till the block inside that function is executed completely? 如果我在ios 5或更高版本上运行,我怎样才能在运行时测试? - how can i test at runtime if i'm running on ios 5 or higher?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM