Newbie trying NSThread
Newbie trying NSThread
- Subject: Newbie trying NSThread
- From: "Tom Watts" <email@hidden>
- Date: Sun, 9 Apr 2006 10:06:55 -0700
I need to create a second thread in my project to handle some work
without disturbing the rest of the app. I think what I am doing wrong
has to do with the run loop, but I just don't know. Here is what I
have going on. This thread needs to keep going until the app quits,
but it is going into the thread, and then the thread immediately dies.
#import "MyApp.h"
@implementation MyApp
- (IBAction)startAction:(id)sender
{
[NSThread detachNewThreadSelector:@selector(myNewThread:)
toTarget:self withObject:nil];
}
- (void)myNewThread:(id)sender
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTimer *myTimer;
NSLog(@"In new thread");
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantFuture]];
do
{
NSLog(@"Starting timer in new thread");
// Do work here
}
while ( [[NSRunLoop currentRunLoop] runMode:NSModalPanelRunLoopMode
beforeDate:[NSDate distantFuture]] );
[myTimer release];
NSLog(@"Leaving new thread");
[pool release];
}
- (void)doSomething
{
NSLog(@"In update function");
return;
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden