HighAccuracyTimers 0.0.2

dotnet add package HighAccuracyTimers --version 0.0.2
                    
NuGet\Install-Package HighAccuracyTimers -Version 0.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HighAccuracyTimers" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HighAccuracyTimers" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="HighAccuracyTimers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HighAccuracyTimers --version 0.0.2
                    
#r "nuget: HighAccuracyTimers, 0.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package HighAccuracyTimers@0.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HighAccuracyTimers&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=HighAccuracyTimers&version=0.0.2
                    
Install as a Cake Tool

High Accuracy Timer

NuGet

An asynchronous timer in C# that runs closer to realtime than the various timers provided by .NET. Inbuilt C# timers run with an accuracy of 12-15ms (according to other things, sample project included so you can see accuracy on your PC vs my timer implementation, see log files in .exe directory). This project aims for sub ms accuracy and minimal drift.

Currently only supports Windows. Windows implementation uses the WaitableTimerExW functions with the CREATE_WAITABLE_TIMER_HIGH_RESOLUTION flag to be as accurate as possible.

Provides a:

  • Windows timer source for close to realtime.
  • A basic scheduler that accounts for drift and skips cycles if overruns happen to catch back up.
    • Provides WaitForNextTickAsync for manually control of when next timer tick is consumed.
    • Provides GetTicksAsync to allow for async foreach loop.
    • Timer tracks start time, but doesn't actively run in background until one of the two async functions are called for getting the next tick. Prevents unnecessary processing
  • A dispatcher to easily support multiple consumers to the same timer.

Usage sample

Single consumer

// Set up platform specific time source
using var timeSource = new HighAccuracyWindowsTimer();

// Create and start scheduler (the timer)
await using var timer = new HighAccuracyScheduler(
    timer: timeSource,
    options: new SchedulerOptions
    {
        Period = TimeSpanUtilties.FromHz(4),
    });

await timer.StartAsync();

// Configure what happens on the timer
// Must be done after timer is started or GetTicksAsync will return immediately
var onTimerTask = Task.Run(async () =>
{
    await foreach (var tick in timer.GetTicksAsync())
    {
        Console.WriteLine("Hello");
    }
});

// Do whatever else your program needs to do
await Task.Delay(TimeSpan.FromSeconds(5));

// Clean up
await timer.StopAsync();
await onTimerTask;

Multiple consumers (using dispatcher)

// Set up platform specific time source
using var timeSource = new HighAccuracyWindowsTimer();

// Create scheduler (the timer)
await using var timer = new HighAccuracyScheduler(
    timer: timeSource,
    options: new SchedulerOptions
    {
        Period = TimeSpanUtilties.FromHz(4),
        StopAfterScheduledTicks = 20,
    });

// Configure dispatcher and subscriptions
await using var dispatcher = new HighAccuracyDispatcher(timer);

// Dispose subscriptions to unsubscribe
using var subscription1 = dispatcher.Subscribe(async (tick, ct) =>
{
    Console.WriteLine("Hello");
});

using var subscription2 = dispatcher.Subscribe(async (tick, ct) =>
{
    await Task.Delay(50, ct);
    Console.WriteLine("Hello again");
});

// Start scheduler
await timer.StartAsync();

// Start dispatcher - must be started after timer
// Will automatically stop and clean up when scheduled number
// of ticks has been reached
await dispatcher.DispatchAsync();
Product Compatible and additional computed target framework versions.
.NET net10.0-windows10.0.17763 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0-windows10.0.17763

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.2 117 4/15/2026
0.0.1 102 4/15/2026