How to know threadid for each thread spawn by parallel.foreach

て烟熏妆下的殇ゞ 提交于 2019-12-22 13:49:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!