Hello,
I started porting over my Foundation stuff over to Cocoa, and I use conventional loops that check for BOOLs at some interval after doing an NSTask, and when the BOOL changes I move out of the loop, like so:
Problem is, when I run this in my Cocoa app, the UI hangs whenever it hits sleep(loopInterval). It comes out of it, but its kinda annoying. I was looking around and maybe I can use NSThread, but that seems overkill for what I am doing. There is also NSTimer, but I guess I am confused about the options as I dont need to notify anything...I just need to sleep for a few seconds and check again. Any ideas as to what I should be doing?
I started porting over my Foundation stuff over to Cocoa, and I use conventional loops that check for BOOLs at some interval after doing an NSTask, and when the BOOL changes I move out of the loop, like so:
Code:
int loopInterval = 20;
BOOL finished;
NSString *appStatus;
while (finished == NO) {
appStatus = [self getAppStatusForAppID: appID];
// just assume getAppStatusForAppID: returns either "Successful" or "Processing"
if (appStatus) {
if ([appStatus isEqualToString:@"Successful"] == YES) {
NSLog(@"instance %@ finished!", appID);
finished = YES;
} else {
NSLog(@"batch status is %@, waiting %d sec to get new status", appStatus, loopInterval);
sleep(loopInterval);
}
} else {
NSLog(@"FAIL");
return 1;
}
}
Problem is, when I run this in my Cocoa app, the UI hangs whenever it hits sleep(loopInterval). It comes out of it, but its kinda annoying. I was looking around and maybe I can use NSThread, but that seems overkill for what I am doing. There is also NSTimer, but I guess I am confused about the options as I dont need to notify anything...I just need to sleep for a few seconds and check again. Any ideas as to what I should be doing?