-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows CTRL_CLOSE not working? #122
Comments
CtrlC runs the signal handler in a separate thread, so it's trying to block that thread. The main thread exists and forcefully exists the signal handling thread as well. I did an implementation few years back that would've solved this issue #60, but as the project was widely adopted already and no one took the time to review the code for bugs, I wasn't brave enough to merge it in. Since then I've left this crate more or less in a maintenance mode. |
@Detegr Could you please share some alternatives that one can use? I was not able to find any suitable. Thanks. |
You can try something inspired on one of the solutions I mention in tokio-rs/tokio#7039 You can also see the concrete workaround I used for my specific case: Another alternative, if you can forego using a Windows Console App, is to use a Windows GUI app. I can't remember whether Ctrl-c implements the Windows GUI signals though. |
@Astlaan Ok, great! Thanks for the response. I'll look into it. |
Adding the
ctrlc
crate toCargo.toml
with thetermination
feature, I tested the code below.I compiled with
cargo build
and then run it by double clicking the executable. Then, when the console spawns, click the X Close button.With the
ctrlc
version, the code didn't work as expected. I expected, after closing the console, for both theX.txt
andm_X.txt
to keep being saved every second, for 5 seconds. However, when I clicked close, they both stop printing right away. The ctrl handler only prints a single file,m_1.txt
.I managed to get it work properly with the
winapi
version, commented in the code below. To test that, just comment thectrlc
code and uncommented that one.What am I doing wrong?
main.rs
Cargo.toml
The text was updated successfully, but these errors were encountered: