简体   繁体   中英

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
    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.
    https://www.quartz-scheduler.net/

  2. A long-running timer (not recommended)

  3. Windows Task Scheduler Task on the Server, triggering an API Method.
    (Suggested by Fildor )

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