• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSThread Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSThread Question
      • From: Lorenzo Puleo <email@hidden>
    • What is NSRuleBook and why to I get exceptions ?
      • From: "Erik M. Buck" <email@hidden>
References: 
 >NSThread Question (From: Lorenzo Puleo <email@hidden>)

  • Prev by Date: Re: Lua (Was: Re: Compile times)
  • Next by Date: Re: NSThread Question
  • Previous by thread: NSThread Question
  • Next by thread: What is NSRuleBook and why to I get exceptions ?
  • Index(es):
    • Date
    • Thread