Scheduled ASP.NET Task

Discussion in 'ASP .Net' started by slY, Jan 12, 2010.

  1. slY

    slY Guest

    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:

    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)
    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

    ' Reset Timer
    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
    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, Jan 12, 2010
    1. Advertisements

  2. Patrice

    Patrice Guest


    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, Jan 12, 2010
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Walsh

    Scheduled Task in J2EE

    Ian Walsh, Sep 11, 2004, in forum: Java
    Wei Jiang
    Sep 13, 2004
  2. knocker

    J2ME Scheduled task?

    knocker, Sep 20, 2004, in forum: Java
    Darryl L. Pierce
    Sep 23, 2004

    Scheduled task

    SLEEPY LOLO, Feb 3, 2005, in forum: C++
    Victor Bazarov
    Feb 4, 2005
  4. upin_cool
    May 15, 2006
  5. Colin Steadman

    Start A Scheduled Task From ASP Server

    Colin Steadman, Feb 25, 2004, in forum: ASP General
    Tom Kaminski [MVP]
    Feb 26, 2004

Share This Page