Re: NSThread Question
Re: NSThread Question
- Subject: Re: NSThread Question
- From: "Erik M. Buck" <email@hidden>
- Date: Tue, 23 Apr 2002 13:29:26 -0500
Give the main event loop a chance to process events and the button will work
correctly without the need to use threads.
- (IBAction)startStopLoop
{
if(isRunning == YES){
// isRunning is a variable instance of this class
isRunning = NO;
return;
}
else
{
isRunning = YES;
[self performSelector:@selector(executeLoop:) withObject:[NSNumber
numberWithInt:0]
afterDelay:0.0];
}
}
- (void)executeLoop:(NSNumber *)cuttentCounter
{
int i = [cuttentCounter intValue];
if(i < [gItemsToDoArray count])
{
[self processTheItem:[gItemsToDoArray objectAtIndex:i]];
}
else
{
isRunning = NO;
// This shows an alert telling how much items
// were been processed
[self showReport:i];
}
if(isRunning)
{
[self performSelector:@selector(executeLoop:) withObject:[NSNumber
numberWithInt:i+1]
afterDelay:0.0];
}
}
----- Original Message -----
From: "Lorenzo Puleo" <email@hidden>
To: <email@hidden>
Sent: Tuesday, April 23, 2002 12:45 PM
Subject: NSThread Question
>
I should have to run/stop a cycle using the same button.
>
>
I would like to break the loop at any time pressing the same button.
>
But when I press the button to start the loop, I can't press again the
>
button to stop the loop. I have to wait the loop ends...
>
Also, the button still appears blue-pressed...
>
>
I understand I have to use NSThread, but I don't understand how I can do
>
this using my current routine since NSThread requires methods (+) which
>
don't allow to manipulate variable instances and factories within
>
theirselves as, instead, I have to do.
>
>
Any ideas would be greatly appreciated as I am relatively
>
new to Cocoa. Thanks.
>
>
>
My current loop would be: (it doesn't work as I want)
>
- (IBAction)ExecuteLoop
>
{
>
int i;
>
if(isRunning == YES){
>
// isRunning is a variable instance of this class
>
isRunning = NO;
>
return;
>
}
>
isRunning = YES;
>
>
// gItemsToDoArray is a variable instance of this class
>
for(i = 0; i<[gItemsToDoArray count]; i++){
>
if(isRunning == NO) break;
>
[self processTheItem:[gItemsToDoArray objectAtIndex:i]];
>
}
>
// This shows an alert telling how much items
>
// were been processed
>
[self showReport:i];
>
}
>
>
--
>
Lorenzo Puleo
>
mailto: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.
_______________________________________________
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.