Re: How to show a progress without multithreading?
Re: How to show a progress without multithreading?
- Subject: Re: How to show a progress without multithreading?
- From: Ken Thomases <email@hidden>
- Date: Sat, 13 Mar 2010 22:49:45 -0600
On Mar 13, 2010, at 10:23 PM, Quincey Morris wrote:
> On Mar 13, 2010, at 19:33, Alexander Bokovikov wrote:
>
>> I have a time-consuming procedure, and I'd like to show its progress. I can't use multi-threading for some technical reason.
>> I'm looking for a way to update a progress indicator from this procedure,
>> As far as I understand my task is to cause message loop processing.
>> And my question is - how to do it?
>
> It's fairly straightforward -- repeatedly invoke a method that does the following:
>
> NSEvent *event;
> while ((event = [NSApp nextEventMatchingMask: NSAnyEventMask
> untilDate: nil inMode: NSEventTrackingRunLoopMode dequeue: YES]))
> [NSApp sendEvent: event];
>
> Make sure this is called often enough for responsiveness (say, at least every 0.1 secs), but not too often to interfere with performance.
>
> You might want to choose a different run loop mode, if you have special requirements. NSEventTrackingRunLoopMode is sufficient to allow keystrokes and mouse clicks to be processed, so that you can have a UI (say, Esc key or button) to cancel the procedure if you want.
You should also see if -beginModalSessionForWindow:/-runModalSession:/-endModalSession: makes sense for your situation. It does require that you can do the time-consuming task in discrete chunks.
Regards,
Ken
_______________________________________________
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