WebApplication.RunAsync does not accept a cancellation token
See original GitHub issueThe documentation says: “Runs an application and returns a Task that only completes when the token is triggered or shutdown is triggered”, But the token is not in the method parameters.
The underlying HostingAbstractionsHostExtensions.RunAsync
accepts a token, so it is not a problem to pass it, it was probably just forgotten.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Add a `cancellationToken` for `WebApplication.RunAsync`
Currently, the WebApplication.RunAsync does not have a CancellationToken parameter, think we should have a CancellationToken to forward it to the inner Host ...
Read more >WebHostExtensions.RunAsync(IWebHost, ...
Runs a web application and returns a Task that only completes when the token is triggered or shutdown is triggered.
Read more >c# - How to cancel webhost when process is stopping
I noticed that the RunAsync takes a cancellation token and I'd like that to be based on the application closing. My question -...
Read more >Cancelling await calls in .NET 6 with Task.WaitAsync()
In this post I discuss the new Task.WaitAsync() APIs introduced in .NET 6 and how you can use them to cancel an await...
Read more >How to use cancellation tokens in ASP.NET Core 7
An async task receives a cancellation token and examines it to see if a cancellation is requested. If so, the current operation should...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I would not call it an “idea”. It is more like a 2-lines quick non-breaking bugfix. Look:
Instead of
https://github.com/dotnet/aspnetcore/blob/e13e3facfb26643fe580be56f2d3f466cd5ee009/src/DefaultBuilder/src/WebApplication.cs#L145-L149
We put
I really don’t think it has to wait until .NET 8… Or am I oversimplifying?
Also, about a workaround: I used
Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync
, which is an extension method onIHost
, and it works onWebApplication
becauseWebApplication
implementsIHost
. Sadly, I can not pass the URL to listen on this way, but there are other ways to set it.Thanks for contacting us.
We’re moving this issue to the
.NET 8 Planning
milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it’s very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.