问题
I have a scenario something like this
int arr[100];
Parallel.Foreach(arr, (a) => { some processing});
Now, this code will spawn 100 child threads, how can I know thread id for each child thread in "some processing" logic.
回答1:
You could use
Thread.CurrentThread.ManagedThreadId
but note that your parallel foreach is not forced to actually create 100 threads.
来源:https://stackoverflow.com/questions/25369399/how-to-know-threadid-for-each-thread-spawn-by-parallel-foreach