Ways of scheduling tasks (without writing windows scheduler) in asp.net

≯℡__Kan透↙ 提交于 2019-12-05 07:55:34
Antonio Bakula

I was investigating Microsoft.Web.Administration assembly Schedule Class to achieve same thing but it seems that class can be used only to schedule IIS worker process restart, here is the example of creating app pools and setting periodical restart.

So only way was to schedule with this was ASP.NET app restart and then in Application_Start do the scheduled work. But that is ugly hack not solution, so at the end I ended up adding scheduling capabilities to our homegrown backup windows service that was allready running on web server, so IMO Quartz.net is the best solution for you. Maybe you could convince your web provider to install Quartz.net all other solutions seems like a hack that will give you more or less problems.

You could simply write an ASP.Net page that performs your task, e.g. sending the mails. Then use an online scheduling service like SetCronJob to call the URL of the page on your server on a schedule.

The downside of this very simple approach is that you are dependent on an external service.

You can take idea from this and put your task in KeepAlive method. Hope! It helps.

I had this very same problem not long ago, and short of using a third party service, there are no great ways around it.

That said, I used the .NET Application Cache object with an expiry time of 24 hours.

Cache["DailyTask"] = true;

Then in my base page class, everytime a page request was made, I checked for the existing of that variable, and if existing, I ran the task. The downside of this is that then you are reliant on there being page requests made to your application.

Lastly, another way I have seen this done, is to set a callback on the cache expiry (CacheItemRemovedCallback method) and then chain that method to insert a new item into the cache which also has a callback and so the cycle repeats.

System.Timers.Timer - http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx

start it up in your global.asax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!