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
<PackageReference Include="Dreamine.Threading.Windows" Version="1.0.0" />
<PackageVersion Include="Dreamine.Threading.Windows" Version="1.0.0" />
<PackageReference Include="Dreamine.Threading.Windows" />
paket add Dreamine.Threading.Windows --version 1.0.0
#r "nuget: Dreamine.Threading.Windows, 1.0.0"
#:package Dreamine.Threading.Windows@1.0.0
#addin nuget:?package=Dreamine.Threading.Windows&version=1.0.0
#tool nuget:?package=Dreamine.Threading.Windows&version=1.0.0
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
DMContainerthrough 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.
Related Packages
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net10.0-windows was computed. |
-
net8.0-windows7.0
- Dreamine.MVVM.Core (>= 1.0.12)
- Dreamine.Threading (>= 1.0.0)
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 |