info: Microsoft.Hosting.Lifetime[0] Now listening on: http://0.0.0.0:8080 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down.
I don't want to use Ctrl + C to shut down the application
info: Microsoft.Hosting.Lifetime[0] Now listening on: http://0.0.0.0:8080 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down.
I don't want to use Ctrl + C to shut down the application
You can run your task in background, either by following the documentation, but I simply prefer using &
after your program name, it will be executed in the background (if linux), and here you have the solution for windows
dotnet core run &
Because it is in the background it is harder to interrupt, you have to find the pid (linux, mac os) or open control task manager (windows)
You can use IWebHost.RunAsync() method. This version does not wait for CTRL+C
An example:
var host = new WebHostBuilder()
.UseKestrel(opt => { })
.UseStartup<Startup>()
.Build();
CancellationTokenSource cts = new CancellationTokenSource();
await host.RunAsync(cts.Token);
On the output you will not see anymore the message "Application started. Press Ctrl+C to shut down.". When you press CTRL+C it will be routed to the main thread from the input pipe as usual.
Starting HTTP Server on port 8080..
Hosting environment: Production
Content root path: D:\wwwroot\
Now listening on: http://0.0.0.0:8080
Now listening on: http://localhost:8080