简体   繁体   English

在Asp.net核心上如何触发动作或方法

[英]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.

相关问题 ASP.NET MVC RemoteAttribute不会在控制器中触发操作方法 - ASP.NET MVC RemoteAttribute does not trigger action method in controller 使用Hangfire for ASP.NET Core的触发器控制器方法 - Trigger Controller Method using Hangfire for ASP.NET Core 使用默认接口方法作为 controller 动作 ASP.NET 核心 - Use default interface method as controller action ASP.NET Core 禁用对 asp.net 核心中的操作方法的模型验证 - Disable a model validation on an action method in asp.net core 如何使 ASP.NET Core 无效/任务操作方法返回 204 No Content - How do I make an ASP.NET Core void/Task action method return 204 No Content 如何使用asp.net核心在action方法中接收通过ajax请求发送的文件和整数 - How to receive a file and an integer sent through an ajax request in action method using asp.net core 如何在 ASP.NET Core MVC 中读取操作方法的属性? - How to read action method's attributes in ASP.NET Core MVC? 如何将字符串从 Angular 发布到 ASP.NET 核心操作方法? - How can I post a string to an ASP.NET Core action method from Angular? ASP.Net Core 2 如何在身份验证后触发/调用代码 - ASP.Net Core 2 how to trigger/call code after authentication 可以调用操作方法(从操作方法)并让ASP.Net Core注入[FromQuery]参数吗? - Possible to call action method (from action method) and let ASP.Net Core inject [FromQuery] params?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM