RE: How to modify Timer interval?
- From: jetan@xxxxxxxxxxxxxxxxxxxx ("Jeffrey Tan[MSFT]")
- Date: Mon, 24 Jul 2006 07:10:03 GMT
Hi Siva,
Thanks for your post!
In addition to PRSoCo's reply, if you want to use single timer, you may
first store the application monitor start time(using DateTime.Now) in a
private field, then in each Timer.Tick event, you may check the value of
DateTime.Now subtracting original stored time, if this value is greater
than 2 hours, you may set Timer.Interval to 30 minutes. In next 2 hours,
you may give it a recheck follow the same logic. The following code snippet
demonstrates this logic:
private DateTime m_storedtime;
private int checkCount = 1;//used to record check count for changing
interval
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Interval = 120000;//2min
this.timer1.Tick+=new EventHandler(timer1_Tick);
m_storedtime = DateTime.Now;
this.timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (checkCount == 1)
{
TimeSpan ts = DateTime.Now.Subtract(m_storedtime);
if (ts.TotalMinutes >= 120)
{
this.timer1.Interval = 1800000;//30min
checkCount=2;
m_storedtime = DateTime.Now;
}
}
else if (checkCount == 2)
{
TimeSpan ts = DateTime.Now.Subtract(m_storedtime);
if (ts.TotalMinutes >= 120)
{
this.timer1.Interval = 3600000;//60min
}
}
}
Hope this helps!
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- RE: How to modify Timer interval?
- From: Siva
- RE: How to modify Timer interval?
- Prev by Date: RE: when compiling project vs 2005 showing errors from other proje
- Next by Date: VS 2003 bug ?
- Previous by thread: RE: Help: Unable to open Web service project in a .net solution.
- Next by thread: RE: How to modify Timer interval?
- Index(es):
Relevant Pages
|