# windows: Improve foreground task dispatching on Windows \(continued\) \(\#23415\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/c66f611037eb895701e2a559d3273b9fbb7d9251)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: c66f611037eb895701e2a559d3273b9fbb7d9251

Requested commit: c66f611037eb895701e2a559d3273b9fbb7d9251

Commit: c66f611037eb895701e2a559d3273b9fbb7d9251

Tree: 99ee207b9ffa4de649b5efc199ba20db16b96323

Author: 张小白

Committer: GitHub

## Message

````
windows: Improve foreground task dispatching on Windows (continued) (#23415)

Closes #22653 again

In PR #23283, I thought that every `runnable` dispatched to the main
thread would correspond to an `EVENT_DISPATCHED` message in the message
queue. However, after testing, some `runnable`s occasionally weren’t
executed.

This PR updated the code as follows:  
```rust
if let Ok(runnable) = self.main_receiver.try_recv() {    <-- before
for runnable in self.main_receiver.drain() {            <-- after
    runnable.run();
}
```

This ensures that runnables are handled more proactively on the main
thread, now we handle `runnable`s with a much higher priority.

A big thanks to @MolotovCherry and @ArthurBrussee for their testing
efforts!

Release Notes:

- N/A
````

## Parents

- [2f1af2ab694a9a273605b8aeaf5e8f5a816628a1](https://git.cafe/gitcafe/zed/commit/2f1af2ab694a9a273605b8aeaf5e8f5a816628a1?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/c66f611037eb895701e2a559d3273b9fbb7d9251?format=markdown)
