On 23 May 2016, at 4:14 PM, Tom Doan <t...@estima.com> wrote:
> 
> I have an menu operation which, before it fully executes, pops up 
> an NSAlert asking a Yes/No question ("Selection Only(Y/N)?") then, 
> depending upon the answer will either apply to the whole list or just 
> the selection. However, no matter what I do (other than putting the 
> operation in a separate thread), the alert box stays on the screen 
> until the operation is done. release doesn't work. orderout on the 
> window doesn't work. Is there any way to do this (other than 
> changing the threading) so the alert box goes away when I'm done 
> with it?

Do I understand correctly that you perform this lengthy operation in direct 
response to the button click in the alert? If so, this is the expected behavior.

{ F : F ∈ any modern framework } works from a run loop. At each pass in the 
loop, the framework looks for the next event to handle (e.g. a click, or the 
need to close a window). After interpreting it (for instance as a button 
click), it calls the appropriate handler, sometimes in your code (such as the 
callback for the alert buttons), sometimes other parts of the framework (such 
as the part that removes a window from the display list).

If your handler immediately executes a lengthy operation without returning to 
the runloop, then the “close the alert” event won’t come up until the lengthy 
operation concludes and your handler returns control to the runloop. Then the 
loop finds the close-alert event, and takes care of it.

Hence the rule that you don’t do _anything_ lengthy on the main (GUI-runloop) 
thread. You can see how using a separate thread would solve your problem. 
Welcome to 2003. 

Apple has gone to great lengths to make threading easy (from the sound of it, 
your case isn’t all that bad), but it can’t hide it from you entirely.

        — F


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to