简体   繁体   中英

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

Task.Run(() => FireAndForgetMethod());

A more robust and safe choice is to use something like Hangfire.io which relies on reliable storage.

BackgroundJob.Enqueue(() => FireAndForgetMethod());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM