给定这样的场景,在低功率机器上运行:
var logFile = File.ReadAllLines("logpath");
var logList = new List<string>(logFile);
Parallel.ForEach(logList.Batch(8), fileLine =>
{
// work on the 8 lines
});
有没有一种简单的方法可以找出在 Parallel.ForEach 进程中产生的最大并发线程数?
最佳答案
使用 Console.WriteLine 或 Logging 跟踪循环中的每个线程。
Parallel.ForEach(logList.Batch(8), fileLine =>
{
// work on the 8 lines
Console.WriteLine("Processing {0} on thread {1}", filename, Thread.CurrentThread.ManagedThreadId);
});
关于c# - 如何查看 Parallel.ForEach 循环中引发的线程数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45610479/