Amr Jer
Amr Jer

Reputation: 55

How to call "Action Result" ASP.NET MVC at specific time (Daily)

I have a system for sending E-mails to users by a specific time . built in ASP.NET MVC4 and has an action result "function" for checking the time of messages and send it if the day of the message is today .

how can I call this action result (daily) -like a scheduler- in efficient way ?

Thanks.

Upvotes: 1

Views: 1937

Answers (4)

nmit026
nmit026

Reputation: 3364

Use Azure Functions, that's exactly what it was built for. It's really good.

https://learn.microsoft.com/en-us/azure/azure-functions/functions-overview

Upvotes: -1

webnoob
webnoob

Reputation: 15934

Whilst a separate service / application would be better, you could use wget.

GNU Wget is a free software package for retrieving files using HTTP, HTTPS and FTP, the most widely-used Internet protocols. It is a non-interactive commandline tool, so it may easily be called from scripts, cron jobs, terminals without X-Windows support, etc.

You would then do something like:

"C:\Program Files (x86)\GnuWin32\bin\wget.exe" --no-check-certificate https://www.exammple.com/YouController/YourAction -O NUL

in a .bat file and set that to run via a windows Scheduled task at the time you require (assuming you don't need to run it less than every 60 seconds - if you do, let me know as I have another way around this using a windows service to call the bat file instead).

Omitting the -O NUL part would also save the output so you could see if everything ran successfully by doing:

public ActionResult YourAction()
{
    //Do your code, get some stats that show it ran properly.
    return Content("Return your stats here.");
}

from your controller action.

Upvotes: 2

You could create a small console application that just calls the API do send out the emails. You can then schedule the console app to run at a specific time using the Windows Scheduler; you can even have it run without showing the console window. See here or here for details on how to schedule a task.

Upvotes: 0

Aht
Aht

Reputation: 593

More efficient will be when you create new application as Windows Service. There u can easy set code to start at specific time. in this solution you will have more flexibility and independent. You can start hire : Windows Service to run a function at specified time

Upvotes: 0

Related Questions