저는 재단 도구를 쓰고 있습니다. 다른 진행중인 작업과 분리하기 위해 스레딩을해야합니다.FoundationTool의 Runloop
스레딩을 시도했지만 지속적으로 충돌이 발생했습니다. 그리고 마침내 나는 내 자신의 runloop을 실행해야하는 이유를 알아 냈습니다.
간단한 예를 들어 도울 수 있습니까? 다음 코드를 시도했지만 작동하지 않습니다. 내가 그것을 실행할 때마다 Exception과 충돌이 발생합니까? 재단 도구에서 스레드를 어떻게 실행합니까?
@interface MyClass : NSObject
{
}
-(void) doSomething;
@end
@implementation MyClass
-(void) RunProcess:
{
printf("test");
}
-(void) doSomething:
{
[NSThread detachNewThreadSelector: @selector(RunProcess:) toTarget:self withObject: nil];
}
@end
int main(void)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
MyClass *myObj = [[MyClass alloc] init],
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 myObj selector:@selector(doSomething:) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
[pool drain];
return 0;
}
-RunProcess :를 구현하는 위치는 어디입니까? – voidzm
이것은 문제를 설명하기 위해 작성한 샘플입니다. 어쨌든 위의 코드를 업데이트했습니다. – MacGeek
예외는 무엇입니까? –