Re: Open a panel in secondary thread?
Re: Open a panel in secondary thread?
- Subject: Re: Open a panel in secondary thread?
- From: Gabriel Zachmann via Cocoa-dev <email@hidden>
- Date: Mon, 23 Mar 2020 15:01:31 +0100
>>> I would not do this. It is widely documented that AppKit API that produce
>>> UI elements, like NSOpenPanel, are _not_ thread safe.
>>
>> Right, and that is why I have to execute any UI code in the main thread,
>> or so I thought.
>> As far as I understand, the dispatch_get_main_queue is executed by the main
>> thread, isn't it?
> Yes
So, why is
dispatch_sync( dispatch_get_main_queue(), block opening a NSOpenPanel )
a bad idea?
>>
>> When the user selects a directory, I collect all files in that sub-tree (aka
>> "scan").
>> That might involve aliases. which means I need to ask the user to open the
>> directory that alias points to.
>> Because that scan can take several seconds (10-20),
>> I wanted to do that scan in a secondary thread so that it can update
>> progress info in the UI.
>
> This is all reasonable… I guess there may be two options, ask the user on
> the main thread, before you are on your background thread,
Would be doable, but would complicate the code, because I would first need to
scan
the whole directory tree for aliases, get user permission , then pass the array
of directories to a secondary thread.
Also, I would like to give the user progress info while the secondary thread is
collecting.
> and only start the background thread after the user answers, or dispatch the
> UI work to the main thread from your background thread as your code sample
> showed.
So my solution is viable ?
Best regards, Gabriel
_______________________________________________
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