• 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: Sandy McGuffog <email@hidden>
  • Date: Fri, 05 Sep 2014 22:49:14 +0200

Difficult to know exactly what's happening in your situation, but I’d be inclined to try something like:

                dispatch_time_t duration = dispatch_walltime(DISPATCH_TIME_NOW, offset_nsec);

                dispatch_after(duration, dispatch_get_main_queue(), ^{

                });

where offset_nsec is long enough to allow the app to complete it’s start-up process

Sandy

On Sep 5, 2014, at 10:31 PM, Jonathan Guy <email@hidden> wrote:

> I’m using a third party c library that requires registering a callback which gets called if the operation encounters an invalid server certificate (should i accept or reject the cert). The callback needs to return yes or no, which I need to get via a UI prompt so the prompt needs to block so I can return appropriately from the callback. So my initial thoughts are “present the cert in a modal window”. So I put the cert in a SFCertificateView in a scroll view and present it in a modal window but it could not be scrolled up and down which was the initial problem. I also tried the SFCertificatePanel with the same problem. After testing I found I couldn’t scroll any scroll view so I knocked up that small bit of code to show as an example. I tried using performSelectorOnMainThread and waiting until completion and this funnily enough works fine in terms of absolutely no UI weirdness but I can’t get a return value from that plus there were other issues.
> There could be any number of operations running concurrently and any one could require validation at any time.
>
> The callback is basically structured like this
>
> 	__block BOOL accept;
>
> 	if ([NSThread isMainThread]) {
> 		accept = [[Controller sharedController] shouldIAccept:certInfo];
> 	}
> 	else {
> 		dispatch_sync(dispatch_get_main_queue(), ^{
> 			accept = [[Controller sharedController] shouldIAccept:certInfo];
> 			// This is where UI starts playing up when the controller shows the cert
> 		});
> 	}
>
> 	return accept;
>
> So the shouldIAccept method needs to block hence runModal. I also just threw the window up and created my own modal loop but same problem.
>
> On 5 Sep 2014, at 19:59, Jens Alfke <email@hidden> wrote:
>
>>
>>> On Sep 5, 2014, at 11:44 AM, Jonathan Guy <email@hidden> wrote:
>>>
>>> when the NSOpenPanel opens all kinds of weirdness is going on. The scroll views scroll very erratically if at all and the directories don't list properly.
>>
>> Well, you've blocked one of the threads that services the global dispatch queue — it's stuck in a dispatch_sync call that won't return until the user dismisses the open panel. I don't know exactly what kinds of problems blocking the queue will cause, but it's definitely not a good idea. (The problems you report sound more severe than what I would guess would happen, but I definitely don't know how concurrent dispatch queues are implemented.)
>>
>> You should rewrite your code to use dispatch_async instead. Then when the modal session completes, call back to the global dispatch queue to finish running your code.
>>
>> (And the whole scenario you're giving sounds like bad UI design — your code shouldn't suddenly pop up a modal panel just because you "need a file from the user". The user should be in control of tasks like opening files. But you may have created an unrealistic scenario just as an example…)
>>
>> —Jens
>
> _______________________________________________
>
> 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


_______________________________________________

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: Doug Hill <email@hidden>
References: 
 >dispatch_sync(dispatch_get_main_queue() UI weirdness (From: Jonathan Guy <email@hidden>)
 >Re: dispatch_sync(dispatch_get_main_queue() UI weirdness (From: Jens Alfke <email@hidden>)
 >Re: dispatch_sync(dispatch_get_main_queue() UI weirdness (From: Jonathan Guy <email@hidden>)

  • Prev by Date: Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
  • 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