Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [NSApp runModalSession] from Carbon app




You should not use runModalSession this way.
See the discussion part in this method documentation:

“You must invoke this method frequently enough in your loop that the window remains responsive to events. However, you should not invoke this method in a tight loop because it returns immediately if there are no events, and consequently you could end up polling for events rather than blocking.

Typically, you use this method in situations where you want to do some additional background processing while the modal loop runs. For example, while processing a large data set, you might want to use a modal dialog to display progress and give the user a chance to cancel the operation. If you want to display a modal dialog and do not need to do any additional work in parallel, use runModalForWindow: instead. When there are no pending events, that method waits idly instead of consuming CPU time.”


This is maybe not clear, but you should use this method only if you plan to do some background processing on the main thread.

If you do some background processing in other thread, do not bother with manual session management and use  - [NSApplication runModalForWindow:] instead.

Basically, your code should be:

CocoaDialog *controller = [[ConvolutionDialog alloc] initWithNib:@"Convolution"];
[NSApp runModalForWindow:[controller window]];
[controller release];


Thanks, Jean-Daniel. I am aware of runModalForWindow and that one should not call runModalSession in a tight loop. But, as I mentioned above, runModalForWindow also blocks my cooperative threads, i.e. the cooperative threads do not execute until runModalForWindow returns . I need some way to bring up a modal cocoa window and still continue executing the cooperative threads. 

Kurt

Could I ask you how you create your thread? I'm using multi-threading with modal window without any issues.
The only issues with runModal i know is that by default, the modal run loop handle only a small subset of run loop sources that does not include network sources for example (so NSURLDownload will not process wil a modal window is running).
But with a multi-threaded application, this is not a problem as each thread has is own runloop and should no be affected by other thread activity.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden

References: 
 >[NSApp runModalSession] from Carbon app (From: Kurt Sutter <email@hidden>)
 >Re: [NSApp runModalSession] from Carbon app (From: Jean-Daniel Dupas <email@hidden>)
 >Re: [NSApp runModalSession] from Carbon app (From: Kurt Sutter <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.