Re: NSProgressIndicator (CallBacks)
Re: NSProgressIndicator (CallBacks)
- Subject: Re: NSProgressIndicator (CallBacks)
- From: Alastair Houghton <email@hidden>
- Date: Wed, 18 Jul 2007 14:36:37 +0100
On 18 Jul 2007, at 12:09, Barry wrote:
Thanks Alastair for the help with callbacks - that's now working.
However I the NSProgressIndicator Bar is not being displayed.
Hmmm. It looks from your original code like you might be doing all
of your work from the UI thread. In order for your code to work
right, you'll have to do the work asynchronously somehow. Broadly
speaking there are two approaches to long-running computation that
will work in an event-driven system like Cocoa:
1. Break your computation up into chunks.
This usually means maintaining some sort of structure describing
how far
you've got, what you're doing, and what you need to do next. On
each call
of your work function, you do a bit of work, update your
structure, then
return.
Typically you'd call a work routine like this using a timer (in
Cocoa, an
NSTimer), or using idle-time processing (you can use
NSNotificationQueue
for this, or alternatively, write a run-loop observer).
2. Use a separate thread (or even a separate process) to do the work.
This is normally easier than (1) because:
- You can write straight-line code rather than having to manually
maintain state ((1)-style solutions often end up as complex state
machines).
- You don't have to worry about making each invocation of your work
routine return quickly (if you use (1) and don't do this, your
UI will
feel like wading through syrup).
However it does complicate matters slightly because you now need
some way
to communicate between your UI thread and your worker thread/
process.
See the following article for more information:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaPerformance/Articles/UnblockUI.html>
If you don't do either of these things, chances are that your
progress bar won't actually update properly, and that things in your
application will be unresponsive while it's busy working. That isn't
what you want, not least because your users will very probably tell
you that your app has crashed (since they'll see the beachball cursor).
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden