如何将此foreach代码转换为Parallel.ForEach? [英] How can I convert this foreach code to Parallel.ForEach?
本文介绍了如何将此foreach代码转换为Parallel.ForEach?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对Parallel.ForEach
感到有些困惑.
Parallel.ForEach
是什么,它的作用是什么?
请不要引用任何MSDN链接.
I am a bit of confused about Parallel.ForEach
.
What is Parallel.ForEach
and what does it exactly do?
Please don't reference any MSDN link.
这是一个简单的示例:
string[] lines = File.ReadAllLines(txtProxyListPath.Text);
List<string> list_lines = new List<string>(lines);
foreach (string line in list_lines)
{
//My Stuff
}
如何用Parallel.ForEach
重写此示例?
推荐答案
string[] lines = File.ReadAllLines(txtProxyListPath.Text);
List<string> list_lines = new List<string>(lines);
Parallel.ForEach(list_lines, line =>
{
//Your stuff
});
这篇关于如何将此foreach代码转换为Parallel.ForEach?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文