S
slY
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
(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