How do i time interrupts in a C# .net core app (on windows) with a precission of max 1 ms (better if possible)

Theo Ekelmans 20 Reputation points
2025-10-01T13:40:30.2+00:00

i want to write a .net console app that needs to log events on 4 inputs using an interrupt, then push an a record of the event "low to high" or "high to low", input nr and a timestamp (1ms or better resolution) into a fifo queue so other threads can process the business logic.

Any advice on acciving the 1 ms or better timing, on either windows or a raspberry pi 5

Windows development | WinUI
{count} votes

Answer accepted by question author
  1. Michael Le (WICLOUD CORPORATION) 6,670 Reputation points Microsoft External Staff Moderator
    2025-12-02T10:45:34.7433333+00:00

    Hello @Theo Ekelmans ,

    Sorry for the late reply.

    Windows is not a real-time operating system, so guaranteeing sub-millisecond interrupt handling is extremely difficult. For more information, see Real-time operating system - Wikipedia.

    This is a non-Microsoft website. The page appears to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classified as PUPs (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it.

    While technically, you can get high-resolution timestamps using System.Diagnostics.Stopwatch; however, the actual event detection latency will depend on the driver and the OS scheduler, which can easily delay several milliseconds.

    Unless you have:

    • A kernel driver optimized for real-time performance.
    • External hardware that captures events and streams timestamps data to your application.

    Without these, achieving reliable <1ms interrupt handling on Windows alone is unlikely.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.