Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8079511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:07:32+00:00 2026-06-05T16:07:32+00:00

Basically i have a problem with this timer program I am trying to put

  • 0

Basically i have a problem with this timer program I am trying to put together. On starting the program it will utilise a steady 25% CPU which i dont mind, but every time the timer fires it adds another 25% on to the CPU so on the 4th pass im completely maxed out.

I take it I’m not disposing of the timer correctly after it has fired but im new to c# and not really sure how to go about this.

the cope of my program is basically:

  • Execute some procedures – once completed start timer
  • Wait until timer elapses then start procedures again, disabling the timer until completed

any help would be greatly appreciated 🙂

private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
    IpCheck();
}

private static void EnableTimer()
{
    System.Timers.Timer aTimer = new System.Timers.Timer();
    // Set the Interval to x seconds.
    aTimer.Interval = 10000;
    aTimer.Enabled=true;
    aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
    aTimer.Enabled = false;
    aTimer.Dispose();
}

ok revised version below – simplified and ruled out the ip check so all it does now is show a message box – this will not even execute anymore 🙁

public class Timer1        
{

    System.Timers.Timer aTimer = new System.Timers.Timer();
    public static void Main()
    {

        Timer1 tTimer = new Timer1();
        tTimer.EnableTimer();

       }


    private void OnTimedEvent(object source, ElapsedEventArgs e)
    {
        aTimer.Enabled = false;
        MessageBoxPrint();
        aTimer.Enabled = true;


    }
    private void EnableTimer()
    {

        // Set the Interval to x seconds.
        aTimer.Interval = 10000;
        aTimer.Enabled=true;
        aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);


    }


    public static void MessageBoxPrint()
    {
        MessageBox.Show("Testing");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:07:34+00:00Added an answer on June 5, 2026 at 4:07 pm

    You’re probably looking for something like this:

    private static System.Timers.Timer aTimer = new System.Timers.Timer();
    
    // This method will be called at the interval specified in EnableTimer
    private static void OnTimedEvent(object source, ElapsedEventArgs e)
    {
        aTimer.Enabled = false;  // stop timer
        IpCheck();
        aTimer.Enabled = true;   // restart timer so this method will be called in X secs
    }
    
    private static void EnableTimer()
    {
        // Set the Interval to x seconds.
        aTimer.Interval = 10000;
        aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
    
        aTimer.Enabled=true;  // actually starts timer
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically have this program which fetches orders from a database. My problem is
I have basically the same problem outlined in this question, however I am using
The problem is basically this, in python's gobject and gtk bindings. Assume we have
This is basically a math problem, but very programing related: if I have 1
I have a problem trying to design some generic storage.. Basically I have the
I have implemented a java program . This is basically a multi threaded service
I have a problem with my BroadcastReceiver. Basically, I have a function in my
I have a pretty simple problem. Basically I have an array called $list that
can anyone help? I have a problem aligning rounded corners in IE6/7. Basically everything
I'm not finding any question specifically with the odd problem I have. Basically I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.