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 6322231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:17:35+00:00 2026-05-24T16:17:35+00:00

I have a slow method, while executing it on timer (System.Timers.Timer). It sometimes gets

  • 0

I have a slow method, while executing it on timer (System.Timers.Timer). It sometimes gets longer to execute than the timer’s timeout, which causes the timer to wait. I want while I set the timer for 30ms for example, after 30ms, to reset the method, not wait. What kind of timer should I use?

EDIT:

void OnTimerElapsed() {
      SomeMethod(args1);
      SomeMethod(args2);
      SomeMethod(args3);
}

SomeMethod is located in another assembly. It’s a sync method which requests data from another application. I don’t know why it sometimes hangs. That causes the timer to pause until SomeMethod() continues.

  • 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-05-24T16:17:37+00:00Added an answer on May 24, 2026 at 4:17 pm

    Use the System.Timers.Timer and set the its AutoReset to false, and only start it when the previous elapsed finished or at your custom condition. Here is the pattern that I use:

    private System.Timers.Timer _timer = new System.Timers.Timer();
    private volatile bool _requestStop = false;
    
    private void InitializeTimer()
    {
        _timer.Interval = 100;
        _timer.Elapced += OnTimerElapced;
        _timer.AutoReset = false;
        _timer.Start();
    }
    
    private void OnTimerElapced(object sender, System.Timers.TimerEventArgs e)
    {
        //_timer.Stop();//if AutoReset was not false
    
        //do work....
    
        if (!_requestStop)
        {
            _timer.Start();//restart the timer
        }
    }
    
    private void Stop()
    {
        _requestStop = true;
        _timer.Stop();
    }
    
    private void Start()
    {
        _requestStop = false;
        _timer.Start();
    }
    

    Edit: If you like to watch the timer and if the operation takes longer time then you should not use timer in the first place, instead use wrap your operation in a new thread and use MaunalResetEvent, use its WaitOne method to specify the timeout, if the timeout occurs then stop or about the operation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app with a large ListView which is terribly slow so I'm
I have a method that gets rows from my database. It looks like this:
I have the following query method that has slow performance: @Override public Map<String, Long>
I have some slow internet task to save and load file, I'd like to
I have a slow custom data source in a SSIS Dataa Flow Task.I have
We have a painfully slow report.I added a Response.flush and it seems a great
I have a Website that is really slow and feels really bad when using
I have a large database of normalized order data that is becoming very slow
If you have a situation where a TCP connection is potentially too slow and
I have a game in XNA which needs to do network calls. In the

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.