How to answer a request but continue processing code in WebApi

后端 未结 1 1977
灰色年华
灰色年华 2020-12-16 18:05

I would like to answer a request, but continue processing code.

I tried something like:

[HttpPost]
public async Task Send         


        
相关标签:
1条回答
  • 2020-12-16 18:46

    I would like to answer a request, but continue processing code.

    Are you sure you want to do this in ASP.NET? This is not a situation that ASP.NET (or any web server) was designed to handle.

    The classic (correct) way to do this is to queue the work to a persistent queue and have a separate backend process do the actual processing of that work.

    There are all kinds of dangers with doing processing inside of ASP.NET outside of a request context. In general, you can't assume that the work will ever actually be done. If you're OK with that (or just like to live dangerously), then you can use HostingEnvironment.QueueBackgroundWorkItem.

    I have a blog post that goes into more detail.

    0 讨论(0)
提交回复
热议问题