question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenFolderDialog freezes the program

See original GitHub issue

Here is a simple example with a OpenFolderDialog which freezes the program. Originally I tried it without the Task.Run() and instead used await for the result but that had the same issue. So I switched to this code after taking a look at https://github.com/AvaloniaUI/Avalonia/issues/1837

 public void SelectFolder()
        {
            var task = Task.Run(() =>
            {
                var dialog = new OpenFolderDialog()
                {
                    Title = "Select Folder...",
                    InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
                };

                var result = dialog.ShowAsync(Application.Current.MainWindow);
                if (result == null)
                {
                    return "Canceled";
                }
                else
                {
                    return "Selected";
                }
            });

            this.statusUpdate = task.GetAwaiter().GetResult();
        }

I am running on Win7 with .net core 3.0 (I also tested .net core 2.1)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kekekekscommented, Jul 16, 2019

It’s not the dialog freezing the program, it’s task.GetAwaiter().GetResult(); causing a deadlock. Use async/await. For more details see TAP.docx.

0reactions
rbnswartzcommented, Apr 6, 2021

For anyone that was like me trying to do this in a non-async method if you put it in a async method then you can just use ShowAsync without needing to do anything else.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Open file dialog freezes the program when I try to use it
I am using visual studio 2017 to create a windows form application, which I am trying to use OpenFileDialog to load an XML...
Read more >
File dialog window makes most program on Windows 11 ...
Hi Hogne, I am Dave, I will help you with this. Your Quick access folder is probably corrupt, the best option is to...
Read more >
Solved: C# Open File Dialog freezes.
I have a browse button on a C# winform just like I have a thousand times before. However, this time when I click...
Read more >
Call to OpenFileDialog or SaveFileDialog hangs or freezes
Today I was debugging a very strange issue when call to OpenFileDialog and SaveFileDialog hanged, froze, never returned…
Read more >
Premiere Pro freezes when trying to open windows file dialog
It's like the dialogue box is hidden and premire is just frozen. I've been fighting this for almost a year. I think i'm...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found