How to execute a method in Asp.net MVC for every 24 hours

前端 未结 6 1532
时光取名叫无心
时光取名叫无心 2020-12-09 06:32

I have method in MVC like

 public void Sendmails()
 {
     //sending mails for every 24 hours.
 }

Can I schedule above method to execute fo

6条回答
  •  旧巷少年郎
    2020-12-09 07:04

    Like everyone said that it is not a good practice to do long running background processes in your .net web application for reliability etc.

    You can create an external trigger that calls into your MVC action method every 24 hours. So you are executing your code every 24 hours. There are multiple ways and services to do that, i have used different services. Or you can create your own if you do not want to use third party.

    For example, you can use pingdom.com free account to call a certain url every period. So in pingdom you can enter the url to your MVC action.

    http://domain/controller/action
    

    And that will be called every 24 hours and your code will run on schedule.

    Update: recently i have been using Azure scheduler, which is build for scenarios like this. https://azure.microsoft.com/en-us/services/scheduler/

提交回复
热议问题