• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dispatch_sync(dispatch_get_main_queue() UI weirdness


  • Subject: Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
  • From: Ken Thomases <email@hidden>
  • Date: Sat, 06 Sep 2014 12:50:07 -0500

On Sep 6, 2014, at 7:59 AM, Rainer Brockerhoff <email@hidden> wrote:

> 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.

Why not do modal stuff in such a block?  I don't think this function is subject to the same serializing problem I described in my previous email.

How is running a modal file dialog or alert from such a block different from running it in code that just uses the main thread (like the action method for the File > Open menu item)?  That is, unless you're advocating against all modal APIs in all circumstances, what makes this different?


> 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?
>   });
> }

-beginWithCompletionHandler: is not a drop-in replacement for -runModal.  In particular, it runs a non-modal dialog.  The user can interact with other windows, etc.  That may be what you want in some cases, but it isn't appropriate in all.

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


  • Follow-Ups:
    • Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
      • From: Rainer Brockerhoff <email@hidden>
References: 
 >Re: dispatch_sync(dispatch_get_main_queue() UI weirdness (From: Rainer Brockerhoff <email@hidden>)

  • Prev by Date: Re: NSOutlineView
  • Next by Date: Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
  • Previous by thread: Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
  • Next by thread: Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
  • Index(es):
    • Date
    • Thread