How to find a thread for each thread generated by parallel.foreach

I have a script similar to this

int arr[100]; Parallel.Foreach(arr, (a) => { some processing}); 

Now this code will spawn 100 child threads, how can I find out the thread identifier for each child thread in the "some processing" logic.

+2
source share
1 answer

you can use

 Thread.CurrentThread.ManagedThreadId 

but note that your concurrent foreach is not forced to actually create 100 threads.

+7
source

All Articles