Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Scheduled ASP.NET Task

Reply
Thread Tools

Scheduled ASP.NET Task

 
 
slY
Guest
Posts: n/a
 
      01-12-2010
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/d...net-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
 
Reply With Quote
 
 
 
 
Patrice
Guest
Posts: n/a
 
      01-12-2010
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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help making a VPN client connection within Windows 2000 Scheduled Task Richard A. Wells Cisco 0 06-29-2005 04:18 PM
J2ME Scheduled task? knocker Java 2 09-23-2004 03:13 PM
Scheduled Task in J2EE Ian Walsh Java 3 09-13-2004 11:30 AM
Scheduled Task script wont run grounghog Microsoft Certification 0 08-12-2004 03:47 PM
Scheduled Task Won't Run Phyllis Computer Support 8 01-08-2004 01:29 AM



Advertisments