RE: How to modify Timer interval?

Tech-Archive recommends: Speed Up your PC by fixing your registry



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.

.



Relevant Pages

  • RE: How to modify Timer interval?
    ... private DateTime m_storedtime; ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ... project analysis and dump analysis issues. ...
    (microsoft.public.vsnet.general)
  • RE: Generating Private Accessors for an Entire Project
    ... and you found following method to re-generate the Private Accessors are ... macro to re-generate all the classes' Private Accessors at once. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.vsnet.general)
  • RE: Validator message disappeared after post back
    ... Based on my test code: ... private RegularExpressionValidator m_vldPhoneNumber; ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • RE: ObjectDataSource not refreshing correctly from a business Obj
    ... private string m_name; ... Compile the web site and add a GridView to Default.aspx, ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Snip~ I do wish that the scum of New Orleans had all
    ... > support it? ... >>You could have added that she told private things she knew about MsP, ... No. Yolonda posted all of her own sordid history on her blog. ... or maps to my home under the cloak of anonymity. ...
    (misc.legal)