Re: Progress bar
Re: Progress bar
- Subject: Re: Progress bar
- From: Shawn Erickson <email@hidden>
- Date: Thu, 10 Nov 2005 16:58:07 -0800
Well my example code for the threaded method wasn't a complete
example, I left a lot up to the reader. The following is little more
complete example (cannot provide much more not knowing the side
effects of having your main thread being able to process events while
you are doing your database work in a secondary thread).
The example sticks with awakeFromNib but it is likely better to
implement applicationDidFinishLaunching: and move your code that
finished up your application launching in there. This was written in
Mail.app so likely have some syntax errors...
- (void)awakeFromNib
{
[NSThread detachNewThreadSelector:@selector(prepareDatabase)
toTarget:self withObject:nil];
}
- (void)prepareDatabase
{
NSAutorelease* pool = [[NSAutorelease alloc] init];
@try {
...create, configure and show splash window...
[myStatusField performSelectorOnMainThread:@selector(setStringValue:)
withObject:@"Setting up database" // TODO - use NSLocalizedString
to fetch localized versions
waitUntilDone:NO];
... setup database ...
[myStatusField performSelectorOnMainThread:@selector(setStringValue:)
withObject:@"Quering database....." // TODO - use
NSLocalizedString to fetch localized versions
waitUntilDone:NO];
... query database ...
[myStatusField performSelectorOnMainThread:@selector(setStringValue:)
withObject:@"Done" // TODO - use NSLocalizedString to fetch
localized versions
waitUntilDone:NO];
... order out and release splash window ...
} @finally {
[pool release];
}
}
The "@try" and "@finally" are enabled as part of Objective-C
exceptions in the build settings. Just comment those out if you don't
care or want to use them.
-Shawn
On Nov 10, 2005, at 3:17 PM, Andrea Salomoni wrote:
Hi,
Thank you very much for reply.
I tryied to use your method... but it still doesn't work.
Il giorno 11/nov/05, alle ore 00:06, Shawn Erickson ha scritto:
For this scenario your options are to explicitly trigger the view
element to draw itself (likely best to use displayIfNeeded) or
rework things such that your long run body of work takes place in
a secondary thread. Using a secondary thread for this work will
allow the main thread to do its normal event loop which includes
asking dirty views to redraw themselves.
If you do want to use a secondary thread then to update status use
something like the following...
[myStatusField performSelectorOnMainThread:@selector(setStringValue:)
withObject:@"Setting up database"
waitUntilDone:NO];
... setup database ...
[myStatusField performSelectorOnMainThread:@selector(setStringValue:)
withObject:@"Quering database....."
waitUntilDone:NO];
...
Personally I would use a secondary thread for this.
-Shawn
_______________________________________________
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