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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shweta LodhaPosted Nov 27, 2014, 11:37 PM
You can use Thread.
CurrentThread.ManagedThreadIdproperty to get ThreadId of currently executing thread.VulpesPosted Nov 28, 2014, 6:09 AM
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.
Shweta LodhaPosted Nov 27, 2014, 11:43 PM
Joginder BangerPosted Nov 27, 2014, 11:43 PM
SukaskhaPosted Nov 27, 2014, 11:39 PM