[英]On Asp.net core how to trigger action or method
I working on Asp.net core project and need on request on one controllers action trigger some method and don't wait for it to finish but respond to caller immediately. 我正在Asp.net核心项目上工作,需要在一个控制器上请求操作触发某种方法,而不是等待它完成,而是立即响应调用者。 How can I accomplish it?
我该怎么做?
You can certainly use a Task for this. 您当然可以为此使用任务。 However, this isn't a good idea because if ASP.NET recycles, your work will disappear.
但是,这不是一个好主意,因为如果ASP.NET回收,您的工作将消失。
Task.Run(() => FireAndForgetMethod());
A more robust and safe choice is to use something like Hangfire.io which relies on reliable storage. 一个更健壮和安全的选择是使用像Hangfire.io这样的东西,它依赖可靠的存储。
BackgroundJob.Enqueue(() => FireAndForgetMethod());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.