Hi, I saw an article on here explaining a simple way of repeating a block of code using the runtime cache (http://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/). I'm using this method to run a feed system so if a new feed is uploaded it will run the next time this code fires. See code below:
public delegate void FeedDelegate();
private static CacheItemRemovedCallback OnCacheRemove = null;
void Application_Start(object sender, EventArgs e) {
AddTask("FeedScheduler", 60);
}
private void AddTask(string name, int seconds) {
OnCacheRemove = new CacheItemRemovedCallback(CacheItemRemoved);
HttpRuntime.Cache.Insert(name, seconds, null, DateTime.Now.AddSeconds(seconds), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, OnCacheRemove);
}
public void CacheItemRemoved(string k, object v, CacheItemRemovedReason r) {
FeedDelegate d = new FeedDelegate(runFeed);
d.BeginInvoke(null, null);
AddTask(k, Convert.ToInt32(v));
}
void runFeed(){
Feeds.run();
}
I'm finding that after a while the code stops running and I can't figure out why. I've set the application pool not to timeout.
Any ideas?