question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebApplication.RunAsync does not accept a cancellation token

See original GitHub issue

The 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:closed
  • Created a year ago
  • Reactions:4
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
alex-ht-workcommented, Sep 23, 2022

this is an interesting idea

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

    public Task RunAsync(string? url = null,  CancellationToken token = default)
    {
        Listen(url);
        return HostingAbstractionsHostExtensions.RunAsync(this, token);
    }

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 on IHost, and it works on WebApplication because WebApplication implements IHost. Sadly, I can not pass the URL to listen on this way, but there are other ways to set it.

1reaction
msftbot[bot]commented, Sep 23, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found