Re: user-stoppable program
Re: user-stoppable program
- Subject: Re: user-stoppable program
- From: email@hidden
- Date: Fri, 26 May 2006 08:24:10 +0200 (CEST)
- Importance: Normal
> Indeed. An alternative option would be to replace the while() with an
> if(), and then use an NSTimer to repeatedly call the "worker" method.
> That would avoid blocking the run loop.
> and then use an NSTimer to repeatedly call the "worker" method.
>That would avoid blocking the run loop.
I tried the code below ; the timer does its job, but the problem is that
clicking the
"Stop It all" button does not stop the process. What am I doing wrong ?
In MyDocument.h :
-(IBAction) goForward /*does one iteration of the loop */
-(IBAction) goOnAndOn /*iterates the loop until the user stops the process */
In MyDocument.m :
-(IBAction) goOnAndOn : (id) sender
{
NSTimer* timer;
if ([StopItAllButton state]==NSOffState) {
NSLog(@"Starting");
timer = [[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(goForward:)
userInfo:nil
repeats:YES] retain];
} else {
NSLog(@"Stopping");
[timer invalidate];
[timer release];
}
}
Ewan
_______________________________________________
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