简体   繁体   English

计划每天早上 8 点在 ASP.NET MVC 中运行一个方法

[英]Schedule to run a method Daily 8 AM in ASP.NET MVC

如何在 ASP.NET MVC 中调用方法例如,在一个方法中,带出一个出生的人的列表,并向他们发送祝贺信息。

There is no code provided but generally, there are several options I could think of:没有提供代码,但一般来说,我能想到几个选项:

  1. The built-in BackgroundService内置的BackgroundService
    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.1&tabs=visual-studio https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.1&tabs=visual-studio

you can create a structure like this in the backgroundservice:您可以在后台服务中创建这样的结构:

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
    while (!stoppingToken.IsCancellationRequested)
    {
        //Do work

        await Task.Delay(timeSpan, stoppingToken);
    }
}
  1. Quartz task scheduler, which might be overkill for your task. Quartz任务调度程序,这对你的任务来说可能有点矫枉过正。
    https://www.quartz-scheduler.net/ https://www.quartz-scheduler.net/

  2. A long-running timer (not recommended)长时间运行的计时器(不推荐)

  3. Windows Task Scheduler Task on the Server, triggering an API Method.服务器上的 Windows 任务计划程序任务,触发 API 方法。
    (Suggested by Fildor ) (由菲尔多推荐)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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