threads in Xcode
threads in Xcode
- Subject: threads in Xcode
- From: Mai Bui <email@hidden>
- Date: Fri, 16 Jul 2004 16:26:11 -0700
Hi,
I'm learning about thread in Cocoa to write the code for our next
experiment.
First, I want to write a program can control a thread by "Start" an
"Stop", the user can start to run by pressing "start" and stop running
by pressing "stop" button while it runs, this is my program:
// for start button
- (IBAction)runButton:(id)sender
{
[sender setEnabled:NO]; // disable the run button
[NSThread detachNewThreadSelector: @selector(RunLoop:) toTarget:self
withObject:nil];
NSLog(@"Endof run\n");
[self performSelectorOnMainThread:@selector(hasStopped)
withObject:NULL waitUntilDone:false];
}
- (void) RunLoop
{
int i;
NSString *str = @"print out the string\n";
for (i=0; i<1500; i++)
{
[statusText insertText:str]; // use insertText since statusText is
NSTextView class
NSLog(@"Running... %d\n",i);
}
}
// for stop button
- (IBAction)stopRun:(id)sender
{
[NSThread exit];
NSLog(@"Stopping!\n");
}
... but it does not work!
Thanks for any suggestion.
My regards,
Mai Bui N.
MPL - SIO
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.