I am writing a Foundation Tool. I have to do the threading to separate to different ongoing tasks.
I tried to do threading but it was continuously getting crashed. And finally I figured out the reason that, I need to have my own runloop running.
Can some one help with with some simple example? I tried following code but it does not work. Every time I run it i crashes with Exception? How can I run a thread in Foundation tool?
@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;
}