5
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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

0

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)

Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81
0

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
Pawel
  • 900
  • 2
  • 10
  • 19