-
|
I've got a problem with the OpenFolderPickerAsync command on Windows and Mac (using 11 preview 8, behaved the same on 11 preview 1). Trying to do what should be a simple thing: throw up a folder picker in the middle of some code. The code is below. I've tried invoking the picker in two ways: once in the normal thread, once in the UI thread. On Windows, using the normal method works as expected (yay), but when you use the UI thread, you never see a picker. On Mac, the normal thread crashes with a nasty NSException, and if you use the UI thread, you never see a picker (changing the dispatcherpriority doesn't seem to help). Here's what the Mac crash looks like when you're not using the UI thread: ??? 0x0000000124867cd3 0x0 + 4907760851 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
This: You should not do sync over async in GUI applications.
Because you blocked UI thread by SelectFolder call above.
Because macOS requires file picker to run on UI thread. In 11.0 there are some hacks to make it work, but these only help with macos, but not mobile/wasm. Make your code properly async. And it will work as designed - asynchronously and on UI thread. |
Beta Was this translation helpful? Give feedback.
-
|
I accept that this is the answer (thanks), but I'm going to need the hack. Let me explain why. For context, this is an install script, which is triggered from a form button. The script obviously does a number of things in a strict order, and doesn't require the calling form/UI to be active or responsive during that process. It also doesn't have to run on IOS or Android. So, this install script (unfortunately) requires the user to be asked for a folder path an arbitrary number of times: this means I can't gather this information into a form field before the install button is pressed. In this particular use case, a modal folder dialog box would have been an ideal solution. But the Gods seem to have decided that my use case is morally corrupt or something. So, if there's a hack here for MacOSX to make this process sane, I'll happily take it: re-factoring entirely satisfactory working code into an asynchronous mess just so I can get this one item of data from the user seems to be the tail wagging the dog. Chris |
Beta Was this translation helpful? Give feedback.
-
|
Ho hum, well, I solved the problem with the minimal amount of faffing by separating out a bit of logic and putting that on a worker thread so I could dispatch the folder request back to the UI thread when necessary. |
Beta Was this translation helpful? Give feedback.
This:
You should not do sync over async in GUI applications.
Because you blocked UI thread by SelectFolder call above.
Because macOS requires file picker to run on UI thread.
In 11.0 there are some hacks to make it work, but these only help with macos, but not mobile/wasm.
Make your code properly async. And it will work as designed - asynchronously and on UI thread.