2016-12-01 1 views
0

내 objective-c 코드 내에있는 AppleScript로 JAR을 시작합니다.목표 - 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"); 
    } 
} 

을 BTW : 직접 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 좀 봐 주시겠습니까? –

관련 문제