2010-05-12 68 views
2

據我瞭解,由GCD提供的線程確實有runloop但沒有源/端口。現在我使用一些通過NSOperationQueue中的AppleEvents調用AppleScript的方法。有時我的應用程序崩潰跟隨stacktrace。GCD和AppleEvents/NSOperationQueue和AppleScript

我的問題:的AppleScript的NSInvocationOperation或NSBlockOperation GCD-線程

  • 我一定要源/端口添加到gcd-的runloop內的AppleEvents的
  • 使用內部

    • 用法線程在使用AppleEvents之前?
    • 我一定要一個源/端口加入到GCD線程的runloop使用之前[CATransaction提交]?
    • 在使用[NSObject performSelectorAfterDelay ...]之前,我必須添加源/端口到gcd線程的runloop嗎?
    • 如果是的話,怎麼樣?
    • 我可以簡單地調用CFRunLoopRunInMode(kCFRunLoopDefaultMode,5.0假); ///或30或者定義的appleevent超時?
     
    .. 
    
    Thread 9: Dispatch queue: 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 GenericComponent 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 bringZFToForegroundZoomOut:orJustLinkFrontMost:toItem:] 2988 
    13 xxx 0x0000000100053556 __-[ZFSelectionTool openWithPreferredApplication:]_block_invoke_516 54 
    14 com.apple.Foundation 0x00007fff86ed87d9 -[NSBlockOperation main] 140 
    15 com.apple.Foundation 0x00007fff86ec906d -[__NSOperationInternal start] 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 
    
    
    ... 
    
    
    Thread 11 Crashed: Dispatch queue: 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 const*, unsigned int, int, unsigned int*) 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 GenericComponent 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 bringZFToForegroundZoomOut:orJustLinkFrontMost:toItem:] 60 
    15 xxx 0x0000000100053556 __-[ZFSelectionTool openWithPreferredApplication:]_block_invoke_516 54 
    16 com.apple.Foundation 0x00007fff86ed87d9 -[NSBlockOperation main] 140 
    17 com.apple.Foundation 0x00007fff86ec906d -[__NSOperationInternal start] 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 
    
    
  • 回答

    0

    注意,AppleScript的組件已限制線程安全。從10.6開始,您可以在非主線程上使用它,但是您需要爲每個線程創建一個新的ComponentInstance。我認爲你可以用OSAKit來做到這一點,否則你將需要使用粗糙的Carbon API。最好的事情取決於你試圖達到的目標(例如,你運行用戶提供的腳本,還是硬編碼到你的應用程序中的腳本,以及通過NSOperationQueue運行它們的動機是什麼)。