Reputation: 315
I am currently facing two problems with asp.net web application
I have timer which calls a function every 3600 ms(1 min) but if the system is ideal say for few minutes, then the timer stops, t o start the timer again i have to access the website through url or restart the server. Why so?
System timer steadily increases the interval through seconds due to which I am not able to compare time with Datetime.now method
Here is the simple code which i have written in global.asax file:
void Application_Start(object sender, EventArgs e)
{
System.Timers.Timer Timer = new System.Timers.Timer();
Timer.Interval = 1000 * 60;
Timer.AutoReset = true;
//Timer.Elapsed += new ElapsedEventHandler(Run);
Timer.Enabled = true;
}
void Run(object source, ElapsedEventArgs e)
{
var time = DateTime.Now.Hour;
var min = DateTime.Now.Minute;
InspectionMailer insp = new InspectionMailer();
// this condition gets failed after few minutes due to increase in time interval
if ((time == 15 && min == 0) || (time == 15 && min == 26) || time == 15 && min == 40)
{
insp.Send("EQT");
}
}
Upvotes: 0
Views: 1579
Reputation: 2588
Go into your IIS settings and change the Application Pool 'Idle Time-out' to something else. I think it defaults to 15 minutes.
IIS > Application Pools > (Right-click) Advanced Settings > Idle time-out (minutes)
To elaborate, your application pool is falling asleep. You have to either increase the idle time-out to prevent it sleeping, or create something additional that hits a URL on a timer to keep it awake.
Upvotes: 1