且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何执行异步“发射后不管”中的ASP.NET Web API操作

更新时间:2022-04-03 03:28:16

你所要求做的是extremely危险。我有一个博客文章解释了为什么这是一个坏主意,包括$ C $下一个 BackgroundTaskManager 键入的东西会去可怕的错误的几率降至最低。不幸的是,即使你注册ASP.NET运行时的工作背景,它仍然是一个坏主意,依赖此行为。

What you are asking to do is extremely dangerous. I have a blog post that explains why this is a bad idea, including code for a BackgroundTaskManager type that minimizes the chance that something will go horribly wrong. Unfortunately, even when you register your background work with the ASP.NET runtime, it's still a bad idea to depend on this behavior.

的妥善解决是让你的WebAPI要求地方的请求到一个可靠的队列(如天青队列),并拥有独立的服务(如Azure的工作者角色)的排队过程。

The proper solution is to have your WebAPI request place a request into a reliable queue (such as Azure Queue), and have an independent service (such as an Azure Worker Role) process that queue.