Progress Bar while Reading a File
Progress Bar while Reading a File
- Subject: Progress Bar while Reading a File
- From: John Nairn <email@hidden>
- Date: Thu, 27 Apr 2006 11:42:57 -0700
I am trying to find the best way to display a progress bar while
reading a file which might take a long time. My current guess is to
detach thread to read the file and put progress bar in modal window.
My goal was to have a timer in the modal run loop to periodically
check and display the progress. The file thread works fine, but the
timer never fires in the modal loop. Below is code fragment. I
thought I had to start a modal session and then add the timer within
that modal loop. The "timer started" message appears, but the time
never fires.
// file reading thread started
[NSThread detachNewThreadSelector:@selector(readFileThread:)
toTarget:self
withObject:[NSArray
arrayWithObjects:fileName,aType,nil]];
// start progress panel
ProgressController *showProgress = [[ProgressController alloc]
initForDocument:self];
NSTimeInterval frameRate = 1./10.;
NSTimer *progressTimer = nil;
NSModalSession session = [NSApp beginModalSessionForWindow:
[showProgress window]];
while(YES)
{ if([NSApp runModalSession:session] != NSRunContinuesResponse)
break;
if(!progressTimer)
{ progressTimer = [NSTimer scheduledTimerWithTimeInterval:frameRate
target:showProgress selector:@selector(checkProgress:)
userInfo:nil repeats:YES];
NSLog(@"timer started");
}
}
[NSApp endModalSession:session];
[progressTimer invalidate];
[showProgress release];
The ProgressController window controller has the method below, but it
never fires and thus the modal loop never ends.
// timer to show progress
- (void)checkProgress:(NSTimer *)myTimer
{
NSLog(@"in timer status &d",[gedcomDoc readStatus]);
if([gedcomDoc readStatus] != READ_INPROGRESS)
[NSApp abortModal];
}
_______________________________________________
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