如何使用任务并行库? [英] How Do I Use Task Parallel Library?
本文介绍了如何使用任务并行库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个填充了文件名的列表。我想写一些内容相同的文件。我希望这是平行发生的。写入文件后,我想从列表中删除文件名。有超过1000个文件要写。我可以在这种情况下使用TPL吗?我该如何在这里实施TPL?
谢谢,
Amrutha。
解决方案
< blockquote>尝试这样的事情:
String text = ...;
FilenameList.AsParallel()。ForAll(filename =>
{
//将文字写入文件名
}
无需从列表中删除文件名,因为它们都处理过一次。
祝你好运!
Hi,
I have a List populated with filenames. I would like to write in those file with same content. I want this to be happen parallel. Once a file is written, i want to remove the filename from the List. There is more than 1000 of files to write. Can i Use TPL in this scenario. How should i implement TPL here?
Thanks,
Amrutha.
解决方案
Try something like this:
String text = ...; FilenameList.AsParallel().ForAll(filename => { // write text to filename }
No need to remove filenames from the list because they are all processed once.
Good luck!
这篇关于如何使用任务并行库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文