2016-12-01 11 views
0

私は目的コードの中にあるApplescriptsを使ってJARを起動します。Objective - Cで新しいスレッドを生成できません

新しいスレッド(NSThread)でこの操作を実行します。

注:私はGCDを使用しましたが、同時実行キューでさえもメインスレッドに の依存関係があるため、助けになりません。

-(void) launchJar{ 
     NSAppleScript *script = [[NSAppleScript alloc] initWithSource:scriptToLaunch]; 
    [script executeAndReturnError:nil]; 

    NSLog(@"hitting this point"); 
} 


int main(int argc, char *argv[]) { 
     @autoreleasepool { 
      MCMCustomURLSchemeHandler *mcmCustomURLHandler = [[MCMCustomURLSchemeHandler alloc] init]; 


        [NSThread detachNewThreadWithBlock:@selector(launchJar) toTarget:[JARLauncher class] withObject:nil]; 



      return NSApplicationMain(argc, argv); 
     } 
    } 

答えて

1

あなたは、自動解放プールにlaunchJarの文を置く必要があります。ところで

- (void)launchJar { 
    @autoreleasepool { 
     NSAppleScript *script = [[NSAppleScript alloc] initWithSource:scriptToLaunch]; 
     [script executeAndReturnError:nil]; 
     NSLog(@"hitting this point"); 
    } 
} 

:あなたは直接NSThreadでスレッドを起動することは避けてください。代わりにNSOperationQueueまたはGCDを試してください。

+0

私はあなたの助言に従い、それを稼働させました。私はlaunchJarメソッドをどこに置いていたかにも問題がありました。 これを解決すると、別の問題が発生しました:http://stackoverflow.com/questions/40904677/how-do-i-ensure-that-i-close-my-app-only-when-all-the-threads -have-finished-exec あなたはそれを見てみることができますか? –

関連する問題