.NET Timers aborting in web application

Discussion in 'ASP .Net' started by Jeff Greenland, Dec 18, 2003.

  1. Hello everyone,

    I am having problems with Timers in a web application. They just seem to
    stop running after 15 minutes or so.

    My web application is set up like this:

    When a user hits a page in the site, that page (.aspx) instantiates a
    compiled class (.DLL). The instantiation process creates a Timer that runs
    in the background to perform tasks every so often (such as notifying clients
    every 24 hours if something is overdue, etc.).

    The problem seems to be that if the site goes idle, the timer just dies
    after awhile. I've searched high and low to find a solution for this, but
    can't seem to find any answers. I have checked the processModel of my
    machine.config and all of the timeout settings are "Infinite".

    So, just for fun, I built one of my timers to run every minute and log some
    text to a file. That way I could tell when it is aborting. I start up the
    application and it prints a line every minute in the log, so I decide to go
    to bed. I look at it in the morning to see that it stopped after 18 lines
    in the log. I probably used the site for about 3 minutes before going to
    bed, so I'm assuming this is a 15 minute timeout.

    Nothing in the timer code tells them to abort or reschedule or anything.
    The only line of code for this timer is to print the line to the log.

    The only solution I have found that works is to use the scheduler (this is a
    Windows 2000 server, by the way) in the control panel. I have created a
    scheduled task to run every 10 minutes that will open Internet Explorer and
    hit my web site, therefore keeping it active (or starting it back up if it
    went idle).

    It seems like there should be a way to keep the timers persistent for an
    infinite amount of time. Could it be the garbage collector destroying an
    object reference? Is it just the web application shutting down?

    Oh, and as another note, the web application doesn't *seem* to be shutting
    down entirely if it is shutting down. I have my system set up so that when
    the first instantiation occurs, a few logs are printed out. That way I can
    see what's happening when the application starts. Every time I change
    web.config or recompile my DLLs, the application restarts (as it should) and
    I see the new logs. However, when I leave my application running overnight,
    then come in in the morning, the application has not shut down because no
    "startup messages" are appearing in my logs. Yet the timers are dying
    still.

    Sorry about the long-winded question, but I thought I needed to provide a
    good amount of information.

    I greatly appreciate any help someone can provide. Thank you in advance for
    looking at this.

    Hegg

    (wasn't sure which NG to post in, so I posted it in 2 of them)
    Jeff Greenland, Dec 18, 2003
    #1
    1. Advertising

  2. With ASP.NET, the application dies once the last session has died. You can
    modify the amount of time that a session will stay alive, but there is no
    way to make it infinite. The class System.Web.SessionState.HttpSessionState
    has an Int32 field called _timeout (accessed through the Timeout property)
    which specifies the number of minutes that a session will stay alive, so you
    could set this value to System.Int32.MaxValue in order to keep it alive as
    long as possible, but you can never keep it alive infinitely. Instead of
    using ASP.NET to run this scheduled process, you should use a Windows
    service that runs this as often as necessary.

    --
    Chris Jackson
    Software Engineer
    Microsoft MVP - Windows Client
    Windows XP Associate Expert
    --
    More people read the newsgroups than read my email.
    Reply to the newsgroup for a faster response.
    (Control-G using Outlook Express)
    --

    "Jeff Greenland" <> wrote in message
    news:...
    > Hello everyone,
    >
    > I am having problems with Timers in a web application. They just seem to
    > stop running after 15 minutes or so.
    >
    > My web application is set up like this:
    >
    > When a user hits a page in the site, that page (.aspx) instantiates a
    > compiled class (.DLL). The instantiation process creates a Timer that

    runs
    > in the background to perform tasks every so often (such as notifying

    clients
    > every 24 hours if something is overdue, etc.).
    >
    > The problem seems to be that if the site goes idle, the timer just dies
    > after awhile. I've searched high and low to find a solution for this, but
    > can't seem to find any answers. I have checked the processModel of my
    > machine.config and all of the timeout settings are "Infinite".
    >
    > So, just for fun, I built one of my timers to run every minute and log

    some
    > text to a file. That way I could tell when it is aborting. I start up

    the
    > application and it prints a line every minute in the log, so I decide to

    go
    > to bed. I look at it in the morning to see that it stopped after 18 lines
    > in the log. I probably used the site for about 3 minutes before going to
    > bed, so I'm assuming this is a 15 minute timeout.
    >
    > Nothing in the timer code tells them to abort or reschedule or anything.
    > The only line of code for this timer is to print the line to the log.
    >
    > The only solution I have found that works is to use the scheduler (this is

    a
    > Windows 2000 server, by the way) in the control panel. I have created a
    > scheduled task to run every 10 minutes that will open Internet Explorer

    and
    > hit my web site, therefore keeping it active (or starting it back up if it
    > went idle).
    >
    > It seems like there should be a way to keep the timers persistent for an
    > infinite amount of time. Could it be the garbage collector destroying an
    > object reference? Is it just the web application shutting down?
    >
    > Oh, and as another note, the web application doesn't *seem* to be shutting
    > down entirely if it is shutting down. I have my system set up so that

    when
    > the first instantiation occurs, a few logs are printed out. That way I

    can
    > see what's happening when the application starts. Every time I change
    > web.config or recompile my DLLs, the application restarts (as it should)

    and
    > I see the new logs. However, when I leave my application running

    overnight,
    > then come in in the morning, the application has not shut down because no
    > "startup messages" are appearing in my logs. Yet the timers are dying
    > still.
    >
    > Sorry about the long-winded question, but I thought I needed to provide a
    > good amount of information.
    >
    > I greatly appreciate any help someone can provide. Thank you in advance

    for
    > looking at this.
    >
    > Hegg
    >
    > (wasn't sure which NG to post in, so I posted it in 2 of them)
    >
    >
    Chris Jackson, Dec 18, 2003
    #2
    1. Advertising

  3. Jeff Greenland

    Alvin Bruney Guest

    Chris,
    I believe his problem is related to the timer being on the page. If the
    timer is moved to global.asax, it will fix the situation since the timer
    becomes global to the application and not susceptible to session ends. The
    advantage of this is the timer dies when the app gets recycled which is a
    nicety. In the OP's post, the problem occurs when the page goes away, or
    gets torn down or session ends, it takes the timer with it.

    Actually I believe it is a bit more complicated than this. I believe the
    timer, running as a background thread, eventually dies when the session end
    event causes this thread to stop executing. Which is why it goes out after
    roughly the session time out. Your solution, while it would work, would
    still not be bullet proof because maxvalue is still a finite number.

    I've put about 20 seconds of thought into this by the way so it may not be
    spot on.

    --
    Regards,
    Alvin Bruney
    Got DotNet? Get it here
    http://home.networkip.net/dotnet/tidbits/default.htm
    "Chris Jackson" <chrisjATmvpsDOTorgNOSPAM> wrote in message
    news:...
    > With ASP.NET, the application dies once the last session has died. You can
    > modify the amount of time that a session will stay alive, but there is no
    > way to make it infinite. The class

    System.Web.SessionState.HttpSessionState
    > has an Int32 field called _timeout (accessed through the Timeout property)
    > which specifies the number of minutes that a session will stay alive, so

    you
    > could set this value to System.Int32.MaxValue in order to keep it alive as
    > long as possible, but you can never keep it alive infinitely. Instead of
    > using ASP.NET to run this scheduled process, you should use a Windows
    > service that runs this as often as necessary.
    >
    > --
    > Chris Jackson
    > Software Engineer
    > Microsoft MVP - Windows Client
    > Windows XP Associate Expert
    > --
    > More people read the newsgroups than read my email.
    > Reply to the newsgroup for a faster response.
    > (Control-G using Outlook Express)
    > --
    >
    > "Jeff Greenland" <> wrote in message
    > news:...
    > > Hello everyone,
    > >
    > > I am having problems with Timers in a web application. They just seem

    to
    > > stop running after 15 minutes or so.
    > >
    > > My web application is set up like this:
    > >
    > > When a user hits a page in the site, that page (.aspx) instantiates a
    > > compiled class (.DLL). The instantiation process creates a Timer that

    > runs
    > > in the background to perform tasks every so often (such as notifying

    > clients
    > > every 24 hours if something is overdue, etc.).
    > >
    > > The problem seems to be that if the site goes idle, the timer just dies
    > > after awhile. I've searched high and low to find a solution for this,

    but
    > > can't seem to find any answers. I have checked the processModel of my
    > > machine.config and all of the timeout settings are "Infinite".
    > >
    > > So, just for fun, I built one of my timers to run every minute and log

    > some
    > > text to a file. That way I could tell when it is aborting. I start up

    > the
    > > application and it prints a line every minute in the log, so I decide to

    > go
    > > to bed. I look at it in the morning to see that it stopped after 18

    lines
    > > in the log. I probably used the site for about 3 minutes before going

    to
    > > bed, so I'm assuming this is a 15 minute timeout.
    > >
    > > Nothing in the timer code tells them to abort or reschedule or anything.
    > > The only line of code for this timer is to print the line to the log.
    > >
    > > The only solution I have found that works is to use the scheduler (this

    is
    > a
    > > Windows 2000 server, by the way) in the control panel. I have created a
    > > scheduled task to run every 10 minutes that will open Internet Explorer

    > and
    > > hit my web site, therefore keeping it active (or starting it back up if

    it
    > > went idle).
    > >
    > > It seems like there should be a way to keep the timers persistent for an
    > > infinite amount of time. Could it be the garbage collector destroying

    an
    > > object reference? Is it just the web application shutting down?
    > >
    > > Oh, and as another note, the web application doesn't *seem* to be

    shutting
    > > down entirely if it is shutting down. I have my system set up so that

    > when
    > > the first instantiation occurs, a few logs are printed out. That way I

    > can
    > > see what's happening when the application starts. Every time I change
    > > web.config or recompile my DLLs, the application restarts (as it should)

    > and
    > > I see the new logs. However, when I leave my application running

    > overnight,
    > > then come in in the morning, the application has not shut down because

    no
    > > "startup messages" are appearing in my logs. Yet the timers are dying
    > > still.
    > >
    > > Sorry about the long-winded question, but I thought I needed to provide

    a
    > > good amount of information.
    > >
    > > I greatly appreciate any help someone can provide. Thank you in advance

    > for
    > > looking at this.
    > >
    > > Hegg
    > >
    > > (wasn't sure which NG to post in, so I posted it in 2 of them)
    > >
    > >

    >
    >
    Alvin Bruney, Dec 18, 2003
    #3
  4. Thanks Chris, I was actually able to find a solution by taking advice from
    Alvin. Basically the simple solution is to create your timers via the
    application_Start() event in your application's "global.asax" file.

    Thanks for the reply, I appreciate it.

    Jeff



    "Chris Jackson" <chrisjATmvpsDOTorgNOSPAM> wrote in message
    news:...
    > With ASP.NET, the application dies once the last session has died. You can
    > modify the amount of time that a session will stay alive, but there is no
    > way to make it infinite. The class

    System.Web.SessionState.HttpSessionState
    > has an Int32 field called _timeout (accessed through the Timeout property)
    > which specifies the number of minutes that a session will stay alive, so

    you
    > could set this value to System.Int32.MaxValue in order to keep it alive as
    > long as possible, but you can never keep it alive infinitely. Instead of
    > using ASP.NET to run this scheduled process, you should use a Windows
    > service that runs this as often as necessary.
    >
    > --
    > Chris Jackson
    > Software Engineer
    > Microsoft MVP - Windows Client
    > Windows XP Associate Expert
    > --
    > More people read the newsgroups than read my email.
    > Reply to the newsgroup for a faster response.
    > (Control-G using Outlook Express)
    > --
    >
    > "Jeff Greenland" <> wrote in message
    > news:...
    > > Hello everyone,
    > >
    > > I am having problems with Timers in a web application. They just seem

    to
    > > stop running after 15 minutes or so.
    > >
    > > My web application is set up like this:
    > >
    > > When a user hits a page in the site, that page (.aspx) instantiates a
    > > compiled class (.DLL). The instantiation process creates a Timer that

    > runs
    > > in the background to perform tasks every so often (such as notifying

    > clients
    > > every 24 hours if something is overdue, etc.).
    > >
    > > The problem seems to be that if the site goes idle, the timer just dies
    > > after awhile. I've searched high and low to find a solution for this,

    but
    > > can't seem to find any answers. I have checked the processModel of my
    > > machine.config and all of the timeout settings are "Infinite".
    > >
    > > So, just for fun, I built one of my timers to run every minute and log

    > some
    > > text to a file. That way I could tell when it is aborting. I start up

    > the
    > > application and it prints a line every minute in the log, so I decide to

    > go
    > > to bed. I look at it in the morning to see that it stopped after 18

    lines
    > > in the log. I probably used the site for about 3 minutes before going

    to
    > > bed, so I'm assuming this is a 15 minute timeout.
    > >
    > > Nothing in the timer code tells them to abort or reschedule or anything.
    > > The only line of code for this timer is to print the line to the log.
    > >
    > > The only solution I have found that works is to use the scheduler (this

    is
    > a
    > > Windows 2000 server, by the way) in the control panel. I have created a
    > > scheduled task to run every 10 minutes that will open Internet Explorer

    > and
    > > hit my web site, therefore keeping it active (or starting it back up if

    it
    > > went idle).
    > >
    > > It seems like there should be a way to keep the timers persistent for an
    > > infinite amount of time. Could it be the garbage collector destroying

    an
    > > object reference? Is it just the web application shutting down?
    > >
    > > Oh, and as another note, the web application doesn't *seem* to be

    shutting
    > > down entirely if it is shutting down. I have my system set up so that

    > when
    > > the first instantiation occurs, a few logs are printed out. That way I

    > can
    > > see what's happening when the application starts. Every time I change
    > > web.config or recompile my DLLs, the application restarts (as it should)

    > and
    > > I see the new logs. However, when I leave my application running

    > overnight,
    > > then come in in the morning, the application has not shut down because

    no
    > > "startup messages" are appearing in my logs. Yet the timers are dying
    > > still.
    > >
    > > Sorry about the long-winded question, but I thought I needed to provide

    a
    > > good amount of information.
    > >
    > > I greatly appreciate any help someone can provide. Thank you in advance

    > for
    > > looking at this.
    > >
    > > Hegg
    > >
    > > (wasn't sure which NG to post in, so I posted it in 2 of them)
    > >
    > >

    >
    >
    Jeff Greenland, Dec 18, 2003
    #4
    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. Willem Oosthuizen

    Aborting Fucntions

    Willem Oosthuizen, Jul 10, 2003, in forum: VHDL
    Replies:
    2
    Views:
    1,046
  2. Stephen Inkpen

    Timers in application web programming

    Stephen Inkpen, Jul 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    340
    Ken Cox [Microsoft MVP]
    Jul 16, 2003
  3. Wayne MJ

    Aborting a _Click event?

    Wayne MJ, Jul 23, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    382
    Wayne MJ
    Jul 23, 2003
  4. Wayne MJ

    Re: Aborting a _Click event?

    Wayne MJ, Jul 25, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    504
    Wayne MJ
    Jul 29, 2003
  5. Shawn B.
    Replies:
    2
    Views:
    533
    Scott Allen
    Apr 28, 2005
Loading...

Share This Page