How to count the amount of concurrent threads in .NET application?

前端 未结 2 1618
-上瘾入骨i
-上瘾入骨i 2020-12-11 14:33

Having read Parallel.ForEach keeps spawning new threads I am still in doubt whether it is a correct method of counting the number of concurrent there threads?

What

2条回答
  •  遥遥无期
    2020-12-11 15:13

    There are different kinds of threads, I think. The operating system's threads for the application you're running, can be counted with:

    int number = Process.GetCurrentProcess().Threads.Count;
    

    It seems to count System.Diagnostics.ProcessThread instances. Maybe you need to count another kind of thread, like "managed threads", so I'm not sure my answer is what you seek.

提交回复
热议问题