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

1
  • What is the problem with ctrl+C ? Could you elaborate ? Commented Mar 6, 2021 at 15:56

2 Answers 2

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)

Sign up to request clarification or add additional context in comments.

1 Comment

No, I mean in the application code Host.CreateDefaultBuilder().ConfigureWebHostDefaults (...
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.