--- lang: ja-jp breaks: true --- # C# 同時に使用可能なスレッドプール数の最小値を変更する。 2021-11-21 ## 以下の方法で変更可能だが、通常は変更したからと言ってパフォーマンスが向上することは無い。この方法で問題が解決する場合は、非同期処理に何らかの不具合がある可能性が高いと思われます。 ```csharp= public static void SetMinThreads(int intActiveWorkerThreads) { // 最小同時生成スレッド数を変更する int workerThreads = -1; int completionPortThreads = -1; // 現在のスレッド数を取得する ThreadPool.GetMinThreads(out workerThreads, out completionPortThreads); if (intActiveWorkerThreads > workerThreads) { // 同時生成スレッド数を変更する bool ret = ThreadPool.SetMinThreads(intActiveWorkerThreads, completionPortThreads); if (ret) { Console.WriteLine($"ThreadPool.SetMinThreads({intActiveWorkerThreads}, {completionPortThreads}) Successful"); } else { Console.WriteLine($"ThreadPool.SetMinThreads({intActiveWorkerThreads}, {completionPortThreads}) FAILED"); } } else { Console.WriteLine($"ThreadPool.SetMinThreads({intActiveWorkerThreads}, {completionPortThreads}) Ignored"); } } ``` ###### tags: `C#` `スレッドプール` `ThreadPool.SetMinThreads`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up