Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我dispatch_async(dispatch_get_main_queue()从几个后台线程调用。但是,有时调度块中的代码似乎没有执行。这可能是因为我异步调度并且线程在主队列可以执行代码之前退出?
dispatch_async(dispatch_get_main_queue()
您是否尝试将 NSLog 放在代码片段的开头以绝对确定它没有执行?有时,带有错误逻辑的 if 语句会预先终止您的代码。(根据我过去的经验;])
dispatch_async() 调用返回的那一刻,调用它的线程是否随后退出并不重要——可以说“请求在系统中”!在那些“偶尔”的情况下,还会发生其他事情。您的程序是否有运行循环或在其主函数末尾调用 dispatch_main() ?不清楚这是否是您描述的 Cocoa/iOS/POSIX 应用程序。