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

  • Home
  • SEARCH
  • 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 6364295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:08:45+00:00 2026-05-25T00:08:45+00:00

So a simple enough question really. How exactly does the interval for System.Timers work?

  • 0

So a simple enough question really.

How exactly does the interval for System.Timers work?

Does it fire 1 second, each second, regardless of how long the timeout event takes or does it require the routine to finish first and then restarts the interval?

So either:

  1. 1 sec….1 sec….1 sec and so on
  2. 1 sec + process time….1 sec + process time….1 sec + process time and so on

The reason I ask this is I know my “processing” takes much less than 1 second but I would like to fire it every one second on the dot (or as close as).

I had been using a Thread.Sleep method like so:

Thread.Sleep(1000 - ((int)(DateTime.Now.Subtract(start).TotalMilliseconds) >= 1000 ? 0 : (int)(DateTime.Now.Subtract(start).TotalMilliseconds)));

Where start time is registered at start of the routine. The problem here is that Thread.Sleep only works in milliseconds. So my routine could restart at 1000ms or a fraction over like 1000.0234ms, which can happen as one of my routines takes 0ms according to “TimeSpan” but obviously it has used ticks/nanoseconds – which would then mean the timing is off and is no longer every second. If I could sleep by ticks or nanoseconds it would be bang on.

If number 1 applies to System.Timers then I guess I’m sorted. If not I need some way to “sleep” the thread to a higher resolution of time i.e ticks/nanoseconds.

You might ask why I do an inline IF statement, well sometimes the processing can go above 1000ms so we need to make sure we don’t create a minus figure. Also, by the time we determine this, the ending time has changed slightly – not by much, but, it could make the thread delay slightly longer causing the entire subsequent sleeping off.

I know, I know, the time would be negligible… but what happens if the system suddenly stalled for a few ms… it would protect against that in this case.

Update 1

Ok. So I didn’t realise you can put a TimeSpan in as the timing value. So I used the below code:

Thread.Sleep(TimeSpan.FromMilliseconds(1000) - ((DateTime.Now.Subtract(start).TotalMilliseconds >= 1000) ? TimeSpan.FromMilliseconds(0) : DateTime.Now.Subtract(start)));

If I am right, this should then allow me to repeat the thread at exactly 1 second – or as close as the system will allow.

  • 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-25T00:08:46+00:00Added an answer on May 25, 2026 at 12:08 am

    IF you have set AutoReset = true; then your theory 1 is true, otherwise you would have to deal with it in code – see the docuementation for Timer on MSDN.

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

Sidebar

Related Questions

Seemingly a simple enough question, but I cannot work it out. I want to
Hopefully the title of my question was clear enough. Here's a really simple version
Simple enough question: I'm using python random module to generate random integers. I want
Seems like a simple enough question but I can't seem to find the answer.
I hope this is a simple enough question for any SQL people out there...
Following on from my last question here OpenXML looks like it probably does exactly
Really simple question but rather than asking for an academic explanation I want to
Here's a really simple question regarding pythonic coding. Given a list, if you want
this seems like a really simple Question...but behold :) Geek name:string Laser geek_id:integer, power:integer
It's simple enough to code up a class to store/validate something like 192.168.0.0/16 ,

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.