I created a .NET Core console application running as a daemon on a Ubuntu 14.04 machine.
I want to stop the service without forcing it, being able to handle a kill event.
How can I achieve this?
.NET Core has considerably evolved since @Stefano's answer a year ago. In .NET Core 2.0, you can now use the well-known AppDomain.CurrentDomain.ProcessExit
event instead of AssemblyLoadContext.Default.Unloading
. It works fine for console applications on Linux, also in Docker.