4

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.

A.R.SEIF
  • 865
  • 1
  • 7
  • 25

1 Answers1

4

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)

Siavash Rostami
  • 1,883
  • 4
  • 17
  • 31
  • 1
    4. Windows Task Scheduler Task on the Server, triggering an API Method. – Fildor Jan 07 '20 at 07:48
  • yea, but that barely falls under the asp.net service. the scheduling part kinda external to the service. – Siavash Rostami Jan 07 '20 at 07:49
  • So? All you do is trigger a logic. All the code is in the ASP.NET MVC Application. That way you can even change the scheduling without touching the App's code or having to restart or anything. – Fildor Jan 07 '20 at 07:50
  • sure. but when enlisting the options i was thinking of more convenient internal ways of doing so, is all :) – Siavash Rostami Jan 07 '20 at 07:53
  • 1
    That granted. But having used Task Scheduler, to me, that's much more convenient than any of the above listed options (for the reasons in above comment). So feel free to add it to your answer, or don't. Your choice. – Fildor Jan 07 '20 at 07:55
  • 1
    @Fildor fair, i'll add this one as well – Siavash Rostami Jan 07 '20 at 07:56
  • I am using DNTScheduler .with nuget Install-Package DNTScheduler -Version 1.1.0 thank you. – A.R.SEIF Jan 07 '20 at 09:30