473,320 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

.NET Timers aborting in web application

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)
Nov 18 '05 #1
3 2005
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" <je**************@netwidedev.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
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)

Nov 18 '05 #2
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:e1**************@TK2MSFTNGP10.phx.gbl...
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" <je**************@netwidedev.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
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)


Nov 18 '05 #3
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:e1**************@TK2MSFTNGP10.phx.gbl...
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" <je**************@netwidedev.com> wrote in message
news:eu**************@TK2MSFTNGP12.phx.gbl...
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)


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dmitry Demchuk | last post by:
Hi everybody. Recently I ran into situation with System.Threading.Timer in my ASP.NET application. I reinstalled Windows on one of my servers and got timers stop firing events after while, they...
1
by: johnny | last post by:
In a multi-threaded application, say a worker thread makes an asynchronous call and specifies a callback method. But before the callback is executed, the thread is aborted by its creator. What is...
0
by: Cider123 | last post by:
I was originally using: System.Windows.Forms.Timer It started to lock my Window Service up, so I went to the next evolution: System.Threading.Timer All was good. I was using it to send...
9
by: Mark Rae | last post by:
Hi, I've seen several articles about using System Timers in ASP.NET solutions, specifically setting them up in Global.asax' Application_OnStart event. I'm thinking about the scenario where I...
1
by: Bamse | last post by:
Hi, can timers be used in webservices? as an example: to check at some time interval an object - Application and for each logged user, check its login period, and if it is greater than 30...
5
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated...
3
by: Maarten | last post by:
Hi In my aplication it seems that my timer slows down everything, is there a better and/or diferent way than using a timer Maarten
4
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts...
7
by: archana | last post by:
Hi all, I am having application in which i am doing asynchronous call.I am using manualresetevent to wait for asynchronous call to complete. I want to stop asynchronous call after certain...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.