Open johnmrncc1701d opened 4 years ago
thank you! you likely just saved me a headache
This worked, thank you!!
Works well, thank you, is there a way for Mac?
@johnmrncc1701d, what went wrong before you called TrySetApartmentState(ApartmentState.STA)
? I'm wondering if there's some problem with my method (where I'm not doing that) that I haven't found yet.
I'm doing it like this, and so far it seems to work well on Windows 10:
public async void PressedLoadButton()
{
var openFilePanelTask = Task.Run(() =>
{
return StandaloneFileBrowser.OpenFilePanel("Choose file", "", "txt", false);
});
await openFilePanelTask;
var pathArray = openFilePanelTask.Result;
// Do whatever you want with pathArray
}
I don't remember. It was very long ago. On Monday, August 14, 2023 at 11:12:24 AM PDT, Tobias Wehrum @.***> wrote:
@johnmrncc1701d, what went wrong before you called TrySetApartmentState(ApartmentState.STA)? I'm wondering if there's some problem with my method (where I'm not doing that) that I haven't found yet.
I'm doing it like this, and so far it seems to work well on Windows 10: public async void PressedLoadButton() { var openFilePanelTask = Task.Run(() => { return StandaloneFileBrowser.OpenFilePanel("Choose file", "", "txt", false); });
await openFilePanelTask;
var pathArray = openFilePanelTask.Result;
// Do whatever you want with pathArray
}
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
I don't remember. It was very long ago.
It was indeed. Thanks for the quick answer anyway!
It is possible to call OpenFilePanel in a (non-UI) thread, but you need to set the thread with TrySetApartmentState(ApartmentState.STA) and then it will work. So it is possible to have the Async version work on Windows. I thought I would share that because of how long it took me to figure it out.