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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:32:46+00:00 2026-05-26T14:32:46+00:00

I need a function to run at a precise time within +/- 1ms. I

  • 0

I need a function to run at a precise time within +/- 1ms. I have tried the following but end up with a 15ms minimum time between execution.

void Main()
{
    System.Timers.Timer timer = new System.Timers.Timer(1);   // executes every 15ms
    timer.Elapsed += new System.Timers.ElapsedEventHandler(myFunction);

    System.Timers.Timer timer2 = new System.Timers.Timer(5);   // executes every 15ms
    timer2.Elapsed += new System.Timers.ElapsedEventHandler(myFunction);

    System.Timers.Timer timer2 = new System.Timers.Timer(20);   // executes every 31ms
    timer3.Elapsed += new System.Timers.ElapsedEventHandler(myFunction);

    timer.Start();
    timer2.Start();
    timer3.Start();

}

void myFunction()
{
    doWord();
}

using Thread.Sleep() obtains the same results.

Synopsis of application.

I will be reading in a file that contains 1553 messages (each with a timestamp). I will need to replay these messages with as close as possible timing that the file contains. The timestamps for the messages are recorded in microsec, but I will only need msec accuracy.

This is done using a DDC 1553 card (PCI Card). I have an analyzer which allows me to view the messages including the delta time between messages to measure my accuracy.

The machine I’m using has a QuadCore with hyperthreading. Using a for(int i=0; …..) I can get accuracy to with .5msec. However this is very inefficient and would prefer to use a more realistic and even more portable method if possible.

  • 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-26T14:32:46+00:00Added an answer on May 26, 2026 at 2:32 pm

    .NET, C#, and even Windows in general are not realtime OSes suitable for very fine timing.

    The worst options include using the Timer classes and Thread.Sleep().

    You can measure timing fairly accurately using the Stopwatch class, but in terms of accurately waiting for a set amount of time to pass.. there’s no built-in mechanism.

    If you could outline exactly what you are trying to do, assuming it’s not motion control, hardware interfacing etc, there is probably a better solution than relying on very accurate timers.

    Update; Neal: if you are interfacing with hardware in a timing-sensitive way, you should use a different solution. You can do a tight loop with Stopwatch, but it will use lots of CPU for as long as you do. And it won’t be accurate enough, probably. E.g.: a PIC chip, an FPGA, an I/O card or interface, anything else basically.

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

Sidebar

Related Questions

I have a Flex client application. I need a clean up function to run
I need to run a JavaScript function onLoad(), but only do it if the
I need to have a function run once when the page is loaded, and
I'm trying to output the following each time a function is run: <object id=video
I need a function that can return the difference between the below two dates
so i need a simple function to run bat file. How to do such
we need run one function periodically in Java web application . How to call
I'm having a JavaScript issue where I need a function to run and complete
I would like to have a VBA function run as soon as Outlook starts
I need a jquery to function to run on page load. I could not

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.