-
Notifications
You must be signed in to change notification settings - Fork 158
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
Use Ctrl+C
instead of allowing any key press to kill the process
#931
Comments
Sounds reasonable. @baronfel, what is the recommended way in dotnet to handle this nowadays? I have a feeling we could use some sort of application host for this. Does that sound familiar? |
The way of least resistance today is the Generic Host, specifically Host Shutdown. But that requires you buying in to the hostbuilder model. If you don't want all that, you can register to the shutdown/term signals yourself. |
Generic host seems reasonable, it could improve the logging story as well. |
Another solution is to do: let private keepAlive () =
// Keep the program alive until the user presses Ctrl+C
Console.CancelKeyPress.AddHandler(fun _ ea ->
ea.Cancel <- true
Log.info "Received Ctrl+C, shutting down..."
exit 0
)
while true do
Console.ReadKey(true) |> ignore Regarding the logging story, we could do something similar to what was done in Fable. Just create an instance of If going with Generic host, I am not sure where it should take place. Should it replace the FSharp.Formatting/src/fsdocs-tool/BuildCommand.fs Line 1376 in 31e0a51
And we map the start / stop / clean up, to the |
Yes, that be great.
Yeah, I'm a little fuzzy on that too. I would suspect creating a new |
More seriously, in general this what you do to keep a program alive and I suspect this is how the
Seems close to what I suppose is needed |
Using
Ctrl+C
is the standard to kill a CLI application.Would you be ok with using that instead of allowing any key press to kill it?
My reason is that it is easy to press a key while the terminal is in focus which kill the process and then user needs to restart the server and wait for it to be available.
The text was updated successfully, but these errors were encountered: