パフォーマンスのライブ グラフを作成するために、アプリケーションが実行しているスレッドの数を調べようとしています。正しい方向に私を指すか、コード例を提供できますか? ありがとう!
23951 次
3 に答える
39
現在のプロセスのThreadsプロパティを確認できます。
System.Diagnostics.Process.GetCurrentProcess().Threads
もちろん、これにはアンマネージ スレッドも含まれます。
于 2012-05-03T22:03:46.590 に答える
2
If you want to see only Managed Threads:
When you debug your application from Visual Studio you could also check out the Threads
and Parallel Stacks
window,
which can be found in the menu under Debug -> Windows
You can see the Thread-Count
(marked green) in the top Threads
window in the picture below
于 2019-10-11T10:48:14.073 に答える
-1
private static int s_threadCount;
private static void MyMethod() {
Interlocked.Increment(ref s_threadCount);
try {
...
} finally {
Interlocked.Decrement(ref s_threadCount);
}
}
于 2012-05-03T22:05:02.197 に答える