Re: Progress Bar while Reading a File
Re: Progress Bar while Reading a File
- Subject: Re: Progress Bar while Reading a File
- From: "Theodore H. Smith" <email@hidden>
- Date: Thu, 27 Apr 2006 19:55:12 +0100
I think you are trying to combine too many techniques.
It's usually a timer, or a thread, or a session+loop, but not all 3
or even 2.
Try just calling the method directly, instead of making a timer.
On 27 Apr 2006, at 19:42, John Nairn wrote:
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