On 9/6/14, 0:22, cocoa-dev-requ...@lists.apple.com wrote: > Date: Sat, 06 Sep 2014 06:18:41 +0800 > From: Roland King <r...@rols.org> > To: Jens Alfke <j...@mooseyard.com> > Cc: Jonathan Guy <jonathan...@mac.com>, cocoa-dev@lists.apple.com > Subject: Re: dispatch_sync(dispatch_get_main_queue() UI weirdness > Message-ID: <1efd71f4-dd4d-4937-a238-348b3c81d...@rols.org> >> >> Why not? I assume Jonathan's -shouldIAccept: is running a nested >> event loop for the modal panel, since it doesn't return till the >> user dismisses it. >> >> (Whether it's a dispatch_sync or a dispatch_async doesn't matter; >> the main thread will be blocked for as long as the block takes to >> run.) >> >> I still think the problem is that you're blocking the >> dispatch-queue's thread for a long time. Try pausing the app while >> the dialog is up and looking at what the various threads are >> doing.
Sidenote: on OS X the best way to run a UI-doing block would be to define this function: void RunBlockOnMainThread(^(void)block) { CFRunLoopPerformBlock([[NSRunLoop mainRunLoop] getCFRunLoop], kCFRunLoopCommonModes, block); } and call that whenever you want something to be performed on the main thread. But never do modal stuff in that block. So the original code would look like: - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { RunBlockOnMainThread (^{ // So my app is doing some background stuff // and I need a file from the user so // code blah blah code RunBlockOnMainThread(^{ NSOpenPanel *op = [NSOpenPanel openPanel]; [op beginWithCompletionHandler:^{ // handle the open panel results here }]; }); // resume code blah blah code <== probably move this into the results block? }); } HTH, -- Rainer Brockerhoff <rai...@brockerhoff.net> Belo Horizonte, Brazil "In the affairs of others even fools are wise In their own business even sages err." http://brockerhoff.net/blog/ _______________________________________________ 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