Dreamine.Threading.Windows 1.0.0

dotnet add package Dreamine.Threading.Windows --version 1.0.0
                    
NuGet\Install-Package Dreamine.Threading.Windows -Version 1.0.0
                    
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="Dreamine.Threading.Windows" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dreamine.Threading.Windows" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Dreamine.Threading.Windows" />
                    
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 Dreamine.Threading.Windows --version 1.0.0
                    
#r "nuget: Dreamine.Threading.Windows, 1.0.0"
                    
#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 Dreamine.Threading.Windows@1.0.0
                    
#: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=Dreamine.Threading.Windows&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Dreamine.Threading.Windows&version=1.0.0
                    
Install as a Cake Tool

Dreamine.Threading.Windows

Dreamine.Threading.Windows provides Windows-specific threading services for Dreamine.Threading.

This package implements platform-dependent features such as CPU affinity, timer resolution, Windows CPU information, and process CPU usage measurement.
It depends on Dreamine.Threading and supplies concrete services for Windows desktop applications.

➡️ 한국어 문서 보기

Purpose

The core Dreamine.Threading package defines abstractions and scheduling policies.
This package provides Windows implementations for those abstractions.

Dreamine.Threading
 ├─ IThreadAffinityService
 ├─ ITimerResolutionService
 ├─ ICpuUsageProvider
 └─ CPU/core-related abstractions

Dreamine.Threading.Windows
 ├─ WindowsThreadAffinityService
 ├─ WindowsTimerResolutionService
 ├─ WindowsCpuInfoProvider
 └─ WindowsProcessCpuUsageProvider

Responsibilities

This package is responsible for:

  • applying CPU affinity to the current Windows thread
  • controlling timer resolution when supported
  • exposing Windows CPU information
  • measuring current process CPU usage
  • providing Windows-specific registration helpers
  • keeping P/Invoke code outside the core threading package

Package Structure

Dreamine.Threading.Windows
├─ Native
│  ├─ Kernel32NativeMethods.cs
│  └─ WinMmNativeMethods.cs
│
├─ Services
│  ├─ WindowsCpuInfoProvider.cs
│  ├─ WindowsProcessCpuUsageProvider.cs
│  ├─ WindowsThreadAffinityService.cs
│  └─ WindowsTimerResolutionService.cs
│
└─ Registration
   └─ DreamineThreadingWindowsRegistration.cs

Services

WindowsThreadAffinityService

Implements:

IThreadAffinityService

It applies CPU affinity to the current Windows thread using Windows native APIs.

CoreIndex = 2
 → current thread affinity mask is set to CPU core 2

WindowsTimerResolutionService

Implements:

ITimerResolutionService

It controls timer resolution using timeBeginPeriod and timeEndPeriod.

This is useful when high precision polling is required, but it should be used carefully because timer resolution may affect the whole system.

WindowsCpuInfoProvider

Provides Windows CPU information such as logical processor count.

Environment.ProcessorCount

WindowsProcessCpuUsageProvider

Implements:

ICpuUsageProvider

It calculates current process CPU usage using:

Process.GetCurrentProcess().TotalProcessorTime
Elapsed wall-clock time
Environment.ProcessorCount

This provider is used by AdaptiveCpuCyclePolicy to apply dynamic delay when CPU usage rises.

Adaptive CPU Delay Integration

With WindowsProcessCpuUsageProvider, zero-interval workers can be throttled by CPU usage.

Example behavior:

CPU >= 70% -> 5 ms delay
CPU >= 50% -> 3 ms delay
CPU >= 30% -> 1 ms delay
CPU <  30% -> 0 ms delay

This is especially useful for FA-style monitoring loops where IntervalMs = 0 is required, but CPU saturation should be controlled.

Registration

Current registration style:

using Dreamine.Threading.Windows.Registration;

DreamineThreadingWindowsRegistration.Register();

This registers Windows-specific services such as:

IThreadAffinityService  -> WindowsThreadAffinityService
ITimerResolutionService -> WindowsTimerResolutionService
ICpuUsageProvider       -> WindowsProcessCpuUsageProvider
WindowsCpuInfoProvider

This package does not extend DMContainer through partial class across assemblies. Registration is provided through a dedicated registration class.

Design Notes

Windows-specific APIs must not be placed inside Dreamine.Threading.

This package exists to preserve the following dependency direction:

Dreamine.Threading
        ↑
Dreamine.Threading.Windows

The core package remains platform-independent, while this package handles Windows-only behavior.

Validation Scenario

This package was validated with the following setup:

High Adaptive Jobs: 5
High Raw Jobs:      5
Normal Jobs:        30
Total Jobs:         40

Observed behavior:

CPU affinity was applied to dedicated workers.
Adaptive workers used process CPU usage to reduce cycle rate.
Raw zero-interval workers ran at full speed.
Normal workers stayed on 100ms polling.
Overall CPU usage remained stable around 25–30% in the sample run.
Dreamine.Threading
Dreamine.Threading.Windows
Dreamine.Threading.Wpf

Status

Implemented:

  • Windows CPU affinity service
  • Windows timer resolution service
  • Windows CPU information provider
  • Windows process CPU usage provider
  • Windows registration helper

Planned improvements:

  • restore-token based affinity recovery
  • configurable timer resolution period
  • richer CPU usage metrics
  • optional core-zero exclusion policy
  • integration tests for Windows-specific behavior

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Dreamine.Threading.Windows:

Package Downloads
Dreamine.MVVM.FullKit

All-in-one package for Dreamine MVVM on WPF. Includes core MVVM modules and automatic source generator integration.

Dreamine.Threading.Wpf

WPF monitoring UI components for Dreamine threading infrastructure.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 125 5/9/2026