1

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.

Amr Jer
  • 55
  • 7
  • I would definitely create a separate application to send out the emails and set up a scheduled task on the server to run it daily. Setting up timers in a web application like this is risky. If the application isn't accessed for a period of time, IIS could unload it and your daily task along with it. – itsme86 Aug 24 '16 at 15:43
  • If you are not that strict to use MVC action, checkout hangfire.io . It's awesome. http://hangfire.io – Developer Aug 24 '16 at 15:44

4 Answers4

2

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.

webnoob
  • 15,747
  • 13
  • 83
  • 165
  • what if the time is on day,hour ,and minute , I mean I want to send the email by specific time , EX: 26/8/2016 03:44 pm ? – Amr Jer Aug 25 '16 at 09:40
  • You can set the scheduled task up to do that. Set it to start at that time and just run every 24 hours. Another thing you could do is add a check in the Action to ensure the time is correct and if not, sleep for a second. – webnoob Aug 25 '16 at 14:54
0

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

Community
  • 1
  • 1
Aht
  • 583
  • 4
  • 25
0

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.

-1

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

nmit026
  • 3,024
  • 2
  • 27
  • 53