问题
I am into shared hosting and they do not allow me to use windows scheduler... So what are the ways of achieving scheduled tasks ie(timed mail) in asp.net... I just saw background process by Jeff Atwood blog... Is it relaible? Or any other ways of doing scheduled tasks...
Then i found quartz.net but i can't find a simple example that embeds quartz.net into an asp.net(without installing a Quartz.Net server as a standalone windows service)... Any suggestion on quartz.net...
回答1:
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.
回答2:
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.
回答3:
.NET Scheduled Timer
or
Databound Schedule controls
回答4:
You can take idea from this and put your task in KeepAlive method. Hope! It helps.
回答5:
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.
回答6:
System.Timers.Timer - http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
start it up in your global.asax
来源:https://stackoverflow.com/questions/3244920/ways-of-scheduling-tasks-without-writing-windows-scheduler-in-asp-net