[Documentation Issue] Clarify Windows Thread Pool Configuration Behavior for NativeAOT Applications
- Dominant language
- No language data
- Stars
- 4.8k
- Forks
- 6.1k
- Avg merge
- 19h 10m
- Merged PRs (30d)
- 268
Description
### Type of issue
Other (describe below)
### Description
#### Problem Summary
The documentation on [Windows Thread Pool Configuration](https://learn.microsoft.com/en-us/dotnet/core/runtime-config/threading#windows-thread-pool) describes how developers can toggle the use of the Windows thread pool using:
1. **`runtimeconfig.json` file**: `System.Threading.ThreadPool.UseWindowsThreadPool`
2. **Environment variable**: `DOTNET_ThreadPool_UseWindowsThreadPool`
3. **MSBuild property**: `UseWindowsThreadPool`
While this behavior is accurate for non-NativeAOT applications, **NativeAOT applications** exhibit different behavior:
- For **NativeAOT applications**, the thread pool configuration **must be determined at build time** using the `UseWindowsThreadPool` MSBuild property.
- Modifying `runtimeconfig.json` (`System.Threading.ThreadPool.UseWindowsThreadPool`) or setting the environment variable (`DOTNET_ThreadPool_UseWindowsThreadPool`) **has no effect on NativeAOT applications**.
This discrepancy is not explicitly stated in the documentation and can lead to confusion for developers.
---
#### Reproduction Steps
1. Create a .NET console application targeting .NET 8.0 or later.
2. Configure the thread pool behavior:
- Modify console csproj file:
```xml
true
```
3. Publish the application in the following modes:
- **Non-NativeAOT**: Standard .NET publishing.
- **NativeAOT**: Using `PublishAot=true`.
4. Attempt to toggle the thread pool behavior by modifying the runtime configuration (`runtimeconfig.json`) or environment variable.
---
#### Observed Behavior
- **Non-NativeAOT applications**:
- The thread pool configuration can be toggled dynamically using `runtimeconfig.json` or environment variables.
- **NativeAOT applications**:
- The thread pool behavior is determined solely at build time based on the `UseWindowsThreadPool` MSBuild property.
- Runtime configurations via `runtimeconfig.json` or environment variables are ignored.
---
#### Expected Behavior
The documentation should explicitly mention that **NativeAOT applications require the thread pool configuration to be finalized at build time** using the `UseWindowsThreadPool` MSBuild property. Runtime configurability (`System.Threading.ThreadPool.UseWindowsThreadPool` or `DOTNET_ThreadPool_UseWindowsThreadPool`) is not supported in NativeAOT.
---
### Suggested Documentation Update
#### Update Section: [[Windows Thread Pool Configuration](https://learn.microsoft.com/en-us/dotnet/core/runtime-config/threading#windows-thread-pool)](https://learn.microsoft.com/en-us/dotnet/core/runtime-config/threading#windows-thread-pool)
Include a note clarifying this behavior:
> **Note**:
> - For **non-NativeAOT applications**, the thread pool configuration can be toggled at runtime using the `runtimeconfig.json` file or environment variables.
> - For **NativeAOT applications**, the thread pool configuration must be determined at build time using the `UseWindowsThreadPool` MSBuild property. Runtime configurations (`System.Threading.ThreadPool.UseWindowsThreadPool` in `runtimeconfig.json` or `DOTNET_ThreadPool_UseWindowsThreadPool` as an environment variable) are not supported.
---
#### Additional Context
This clarification will help developers better understand the distinction between NativeAOT and non-NativeAOT behaviors, ensuring proper configuration for their applications.
If additional testing or details are needed, I am happy to provide further assistance. Thank you!
### Page URL
https://learn.microsoft.com/en-us/dotnet/core/runtime-config/threading
### Content source URL
https://github.com/dotnet/docs/blob/main/docs/core/runtime-config/threading.md
### Document Version Independent Id
609c4ded-92cf-873b-26f0-a6f654e3728c
### Article author
@gewarren
### Metadata
* ID: dfd449c7-1c94-8e2b-7cdf-01e448d6cac3
* Service: **dotnet-fundamentals**
[Related Issues](https://github.com/dotnet/docs/issues?q=is%3Aissue+is%3Aopen+609c4ded-92cf-873b-26f0-a6f654e3728c)
Contributor guide
Assessment
This issue has not been assessed yet.