Hi,
I have an application in which I am uploading some files to some place using parallel foreach. Now I am looking for a way, in which I can see how many threads are working currently. Is there any way for this?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Shweta LodhaRank #31 · 39.8K reputationPosted Nov 27, 2014, 6:37 PM EST
You can use Thread.
CurrentThread.ManagedThreadIdproperty to get ThreadId of currently executing thread.Sukaskha131 reputationPosted Nov 27, 2014, 6:39 PM EST
Joginder BangerRank #360 · 7K reputationPosted Nov 27, 2014, 6:43 PM EST
Shweta LodhaRank #31 · 39.8K reputationPosted Nov 27, 2014, 6:43 PM EST
VulpesRank #55 · 29.2K reputationPosted Nov 28, 2014, 1:09 AM EST
However, a couple of points to note:
1. On my Windows 7 machine using .NET 4.0, the above apparently single threaded console app still has 4 threads running. Apart from the primary thread there are 3 system threads running namely: the GC thread, the finalization thread and another thread for general house-keeping. Moreover, this is in release mode. If you're running in debug mode, there will be even more threads running.
2. Managed threads are not necessarily the same as operating system threads because the former may be running on lightweight threads known as 'fibers' and several of these may be associated with the same operating system thread.