Prev: Auto Refresh gridview
Next: AJAX UpdatePanel lost focus
From: slY on 12 Jan 2010 12:08 I'm trying to write a piece of code that executes a task every n hours (retrieving data via a Web Service). I checked the web and I found this solution: http://blog.apterainc.com/software/dotnet/scheduled-aspnet-task-aspnet-cron-jobs/ It seems to be very simple, but I have a couple of doubts. Can somebody help me? That are few simple functions used in the previously example: Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) RegisterCacheEntry() End Sub Private Sub RegisterCacheEntry() If HttpContext.Current.Cache(CacheKey) Is Nothing Then HttpContext.Current.Cache.Add(CacheKey, "WebScheduler", Nothing, Caching.Cache.NoAbsoluteExpiration, _ TimeSpan.FromMinutes(1), CacheItemPriority.NotRemovable, _ New CacheItemRemovedCallback(AddressOf CacheItemRemovedCallback)) End If End Sub Private Sub CacheItemRemovedCallback(ByVal key As String, ByVal value As Object, ByVal reason As CacheItemRemovedReason) ' Call To Do Scheduled Task ScheduledTask.Task() ' Reset Timer ResetTimer() End Sub Private Sub ResetTimer() Dim Client As New Net.WebClient Dim strReset As String = Client.DownloadString(ResetPage) End Sub Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) If HttpContext.Current.Request.Url.ToString = ResetPage Then RegisterCacheEntry() End If End Sub Well, the author says that we use ResetPage to "make a call to dummy page on your website". But what is ResetPage? is it a real web page or can it be a fake one? I think it should be a real one because the call Client.DownloadString(ResetPage) will raise an exception in case of a fake resource, right? Can you image a different solution? (avoiding the implementation of a Windows Service) PS: a colleague of mine suggested me not to use Application_Start because it is not so clear when this event is raised, do you agree? Thank you very much, slY
From: Patrice on 12 Jan 2010 12:29 Hello, Don't you have a computer on which you could run a scheduled task ? ASP.NET is just no intended to perform this. My personal preference is by far to create a scheduled task on one of our server (or perhaps a service depending what is does) and run this there... IMO this ASP.NET solution could help if you have no server in house and want for example to do that using a hosted website... If you still want/need to go this route : > But what is ResetPage? is it a real web page or can it be a fake one? IMO just a real one that does nothing. The goal is to keep the site alive. > Can you image a different solution? (avoiding the implementation of a > Windows Service) Why ? Is having this dummy page a problem ? To suggest another one it would be betetr to first known what you don't like with the dummy page. > Application_Start It is raised when the application starts. Not sure what is the problem ? (a confusion with Session_End ?) That said I agree that populating a cache entry in Application_Start is perhaps not a general good idea. As soon as you start to change how data are cached, it can begin to be a bad solution. A more general approach is to put data in the cache when needed when d ata are requested. This approach will work regardless of how data are cached. -- Patrice
|
Pages: 1 Prev: Auto Refresh gridview Next: AJAX UpdatePanel lost focus |