A.R.SEIF
A.R.SEIF

Reputation: 873

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

how Call Method in ASP.NET MVC For example, in one method, bring out a list of people who are born and send them a congratulatory message.

Upvotes: 5

Views: 2149

Answers (1)

Siavash Rostami
Siavash Rostami

Reputation: 1933

There is no code provided but generally, there are several options I could think of:

  1. The built-in BackgroundService
    https://learn.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)

Upvotes: 5

Related Questions