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:

    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
     
    slY, Jan 12, 2010
    #1
    1. Advertising

  2. slY

    Patrice Guest

    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
     
    Patrice, Jan 12, 2010
    #2
    1. Advertising

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
    Replies:
    3
    Views:
    3,697
    Wei Jiang
    Sep 13, 2004
  2. knocker

    J2ME Scheduled task?

    knocker, Sep 20, 2004, in forum: Java
    Replies:
    2
    Views:
    632
    Darryl L. Pierce
    Sep 23, 2004
  3. SLEEPY LOLO

    Scheduled task

    SLEEPY LOLO, Feb 3, 2005, in forum: C++
    Replies:
    7
    Views:
    684
    Victor Bazarov
    Feb 4, 2005
  4. upin_cool
    Replies:
    0
    Views:
    4,680
    upin_cool
    May 15, 2006
  5. Colin Steadman

    Start A Scheduled Task From ASP Server

    Colin Steadman, Feb 25, 2004, in forum: ASP General
    Replies:
    4
    Views:
    402
    Tom Kaminski [MVP]
    Feb 26, 2004
Loading...

Share This Page