据我了解,GCD 提供的线程确实有一个运行循环,但没有源/端口。现在我使用一些在 NSOperationQueue 中通过 AppleEvents 调用 AppleScripts 的方法。有时我的应用程序会因以下堆栈跟踪而崩溃。
我的问题:
- 在 NSInvocationOperation 或 NSBlockOperation 中使用 AppleScript
- 在 GCD 线程中使用 AppleEvents
- 在使用 AppleEvents 之前,我必须将源/端口添加到 gcd 线程的运行循环吗?
- 在使用 [CATransaction commit] 之前,我是否必须将源/端口添加到 gcd 线程的运行循环?
- 在使用 [NSObject performSelectorAfterDelay...] 之前,我是否必须将源/端口添加到 gcd 线程的运行循环?
- 如果是,如何?
- 我可以简单地调用 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 5.0, false); /// 或 30 或 appleevent 定义的超时时间?
.. 线程 9:调度队列:com.apple.root.default-priority 0 libSystem.B.dylib 0x00007fff88276e82 semaphore_wait_signal_trap 10 1 libSystem.B.dylib 0x00007fff8827c3cd pthread_mutex_lock 469 2 com.apple.applescript 0x000000011d3d461f AppleScriptComponent 50 3 com.apple.applescript 0x000000011d3edbcc AGenericCall::Delegate(ComponentInstanceRecord*) 46 4 com.apple.applescript 0x000000011d3ed520 AGenericManager::HandleOSACall(ComponentParameters*) 54 5 com.apple.applescript 0x000000011d3ed4b0 通用组件 219 6 com.apple.openscripting 0x00007fff8381c6da OSAExecuteEvent 63 7 com.apple.Foundation 0x00007fff86f320d8-[NSAppleScript(NSPrivate)_executeAppleEvent:withMode:error:] 161 8 xxx 0x0000000100048af0 -[TCallScript callScript:withArrayOfParameters:] 480 9 xxx 0x0000000100048ffd-[TCallScript callHandler:withParameters:] 477 10 xxx 0x0000000100036032-[ZFOpenWindowController getSafariItemForCurrentTabForWindow:] 66 11 xxx 0x00000001000346af -[ZFOpenWindowController refreshWindowList:] 1679 12 xxx 0x000000010003541c -[ZFOpenWindowController 带来ZFToForegroundZoomOut:或JustLinkFrontMost:toItem:] 2988 13 xxx 0x0000000100053556 __-[ZFSelectionTool openWithPreferredApplication:]_block_invoke_516 54 14 com.apple.Foundation 0x00007fff86ed87d9 -[NSBlockOperation 主] 140 15 com.apple.Foundation 0x00007fff86ec906d -[__NSOperationInternal 开始] 681 16 com.apple.Foundation 0x00007fff86ec8d23 ____startOperations_block_invoke_2 99 17 libSystem.B.dylib 0x00007fff882b2ce8 _dispatch_call_block_and_release 15 18 libSystem.B.dylib 0x00007fff88291279 _dispatch_worker_thread2 231 19 libSystem.B.dylib 0x00007fff88290bb8 _pthread_wqthread 353 20 libSystem.B.dylib 0x00007fff88290a55 start_wqthread 13 ... 线程 11 崩溃:调度队列:com.apple.root.default-priority 0 com.apple.applescript 0x000000011d40f658 BCHandleError() 182 1 com.apple.applescript 0x000000011d4059ca UASExecute1() 2546 2 com.apple.applescript 0x000000011d3dd1d5 ASExecuteEvent(AEDesc 常量*,无符号整数,整数,无符号整数*)695 3 ...ple.CoreServices.CarbonCore 0x00007fff85388e04 CallComponentFunction 28 4 com.apple.applescript 0x000000011d3d4cad AppleScriptComponent 1728 5 com.apple.applescript 0x000000011d3edbcc AGenericCall::Delegate(ComponentInstanceRecord*) 46 6 com.apple.applescript 0x000000011d3ed520 AGenericManager::HandleOSACall(ComponentParameters*) 54 7 com.apple.applescript 0x000000011d3ed4b0 通用组件 219 8 com.apple.openscripting 0x00007fff8381c6da OSAExecuteEvent 63 9 com.apple.Foundation 0x00007fff86f320d8-[NSAppleScript(NSPrivate)_executeAppleEvent:withMode:error:] 161 10 xxx 0x0000000100048af0 -[TCallScript callScript:withArrayOfParameters:] 480 11 xxx 0x0000000100048ffd-[TCallScript callHandler:withParameters:] 477 12 xxx 0x0000000100035c67-[ZFOpenWindowController getItemForAXDocumentOfFrontMostWindow] 119 13 xxx 0x00000001000359f1-[ZFOpenWindowController getItemForFrontMostWindow:] 721 14 xxx 0x00000001000348ac -[ZFOpenWindowController 带来ZFToForegroundZoomOut:或JustLinkFrontMost:toItem:] 60 15 xxx 0x0000000100053556 __-[ZFSelectionTool openWithPreferredApplication:]_block_invoke_516 54 16 com.apple.Foundation 0x00007fff86ed87d9 -[NSBlockOperation 主] 140 17 com.apple.Foundation 0x00007fff86ec906d -[__NSOperationInternal 开始] 681 18 com.apple.Foundation 0x00007fff86ec8d23 ____startOperations_block_invoke_2 99 19 libSystem.B.dylib 0x00007fff882b2ce8 _dispatch_call_block_and_release 15 20 libSystem.B.dylib 0x00007fff88291279 _dispatch_worker_thread2 231 21 libSystem.B.dylib 0x00007fff88290bb8 _pthread_wqthread 353 22 libSystem.B.dylib 0x00007fff88290a55 start_wqthread 13