I would not do this. It is widely documented that AppKit API that produce UI elements, like NSOpenPanel, are _not_ thread safe. So you may find your app hitting some memory stomping issues or strange crashes/exceptions due to this. Specifically what problems you will hit are anyones guess, but its just a matter of time. There is a reason Xcode has the Main Thread Checker to catch UI elements being used on secondary threads.
Lets come at this from a different direction: What are you trying to do? Why do you think you need to use the open panel on a secondary thread? —Rob > On Mar 22, 2020, at 1:11 PM, Gabriel Zachmann via Cocoa-dev > <cocoa-dev@lists.apple.com> wrote: > >> >> Don't know if this helps you but you can look into dispatch_sync >> and dispatch_async. >> > > Thanks a lot! > That made things very easy. > > I am opening the panel now with this piece of code: > > __block NSURL * user_permitted_url; > __block long int result; > // UI stuff must be executed in the main thread > dispatch_sync( dispatch_get_main_queue(), ^(void) > { > result = [self askUserToOpenDirectory: resolvedurl > newURL: & user_permitted_url]; > } > ); > > (where my method askUserToOpenDirectory opens the NSOpenPanel and gets the > URL.) > > BTW: > just in case others stumble over this: > in my case, I am opening the NSOpenPanel with the directory set to > resolvedurl, for which I am asking permission. So the user is just supposed > to click "OK". > So, I thought, I don't need to do anything else; > but it turns out I get permission from the OS really only if I actually get > the URL using > oPanel.URL > , even if it is the same as resolvedurl! > > > Best regards, Gabriel > > > _______________________________________________ > > 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/petrock%40mac.com > > This email sent to petr...@mac.com _______________________________________________ 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