PolyMeilex / rfd

Rusty File Dialog
MIT License
524 stars 60 forks source link

AsyncFileDialog blocks on Windows #190

Closed valadaptive closed 2 months ago

valadaptive commented 2 months ago

AsyncFileDialog should allow the application to continue running while the file dialog is open, but on Windows, it causes it to freeze and eventually cause a "not responding" popup. This seems to be due to mutex shenanigans where ThreadFuture locks the mutex immediately in the thread that it spawns, then blocks on it when you poll it.

Dangerise commented 2 months ago

In fact, even AsyncFileDialog is block, .await means the task will blocked until it complete

to solve it, I think you should spawn another task to call AsyncFileDialog , and let your main loop check whether it is completed.

valadaptive commented 2 months ago

In fact, even AsyncFileDialog is block, .await means the task will blocked until it complete

That's not how Futures work in Rust. When you await a future, it doesn't block the thread; it causes the task to "yield" (within whatever executor you're using, it'll move on to the next task to be executed, and probably won't poll that future again until the task is awoken).

Dangerise commented 2 months ago

@valadaptive I mean, the thread won't be blocked, but the task will be blocked, even it's async

valadaptive commented 2 months ago

Yes, but in the current code, the thread that the executor is running on is blocked, because the future blocks when polled. This means that no other futures can be executed while the file dialog is open, and if the executor is running on the main thread, the application itself will freeze. That's what I'm fixing.

valadaptive commented 2 months ago

Resolved by #191