Re: Progress Bar while Reading a File
Re: Progress Bar while Reading a File
- Subject: Re: Progress Bar while Reading a File
- From: Ryan Britton <email@hidden>
- Date: Thu, 27 Apr 2006 11:59:36 -0700
+[NSTimer scheduledTimerWithTimeInterval:....:] adds the timer to the
default run loop mode of the current run loop. When you're running a
modal session, the run loop is not in default mode but in
NSModalPanelRunLoopMode so the timer never gets processed until the
modal session is over. You'll need to add the timer to the correct
mode first.
On Apr 27, 2006, at 11:42 AM, 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
_______________________________________________
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