Need job scheduler in asp.net

后端 未结 9 2141
無奈伤痛
無奈伤痛 2021-02-03 14:01

We have a website where we need a scheduler to receive notifications (e-mail) on specific time. eg. a person setting reminder at 5 PM to attend the meeting at 4:45 PM, will rece

相关标签:
9条回答
  • 2021-02-03 14:58

    If you really have no control over the server (meaning, you cannot use an sql job, a scheduled task, or install a windows server) then you could use a System.Threading.Timer that you initialize in your Global.asax (e.g, on application startup) that invokes a certain method in your application every x minutes. This method would then query your database and see what notifications need to be send.

    This is really not a desirable approach though, as the timer is not guaranteed to always invoke as far as I know, since, like Peter says, your web application is not guaranteed to be alive at all times.

    However, depending on your requirements, it can still be a 'good enough' approach if you have no other options.

    0 讨论(0)
  • 2021-02-03 14:59

    It's really not desirable to do, but you can do what Razzie is suggesting. I have seen it done many times. Although ugly, sometimes ya just have to do the ugly hacks.

    Using this method though, you have to make sure you application is not unloaded. So you need some sort of keep alive. I would suggest setting up a web monitoring tool that will constantly pull a page (aspx) to keep the application alive. These guys are free http://mon.itor.us/

    0 讨论(0)
  • 2021-02-03 15:05

    With ASP.NET you are not guaranteed that your app is alive at all times, and thus web applications as a host process for a scheduling solution is not feasible IMO.

    A Windows service is what you need for this scenario. You have full control on starting and stopping the process as well as ways of monitoring the application.

    Are you able to host such a service on a different machine? Even if the web application is running on a hosted server doesn't mean you have to run the scheduler on the same server.

    0 讨论(0)
提交回复
热议问题