并行编程 C# 4.0 Task.StartNew
我正在尝试使用新的 .NET 4.0 任务并行库
inputList1 is List<CustomObject>
inputList2 is List<DateTime>
List<double> firstCall = GetDoubleListing(inputList1, inputList2);
List<double> secondCall = GetAnotherListing(inputList3, inputList2);
inputList2 处理两个独立的任务,这在两个调用中都很常见(它是一个只读列表)。
我尝试使用以下代码,但不断出现异常
Task[] tsk = {
Task<List<double>>.Factory.StartNew(GetDoubleListing(inputList1, inputList2)),
Task<List<double>>.Factory.StartNew(GetAnotherListing(inputList3, inputList2));
};
有人可以指导我如何传递参数以及如何启用任务并行库。
I am trying to process 2 independent tasks using the new .NET 4.0 Task Parallel Library
inputList1 is List<CustomObject>
inputList2 is List<DateTime>
List<double> firstCall = GetDoubleListing(inputList1, inputList2);
List<double> secondCall = GetAnotherListing(inputList3, inputList2);
inputList2 is common in both the calls ( it is a read only list ).
I tried to use the following code but kept getting exceptions
Task[] tsk = {
Task<List<double>>.Factory.StartNew(GetDoubleListing(inputList1, inputList2)),
Task<List<double>>.Factory.StartNew(GetAnotherListing(inputList3, inputList2));
};
Can someone guide me as to how to pass parameters and how to enable Task Parallel Library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您只想并行完成
GetDoubleListing()
和GetAnotherListing()
调用。StartNew()< 的重载/code>
需要代表。由于参数没有改变,您可以使用 lambda 进行调用,如下所示:
It appears you just want the
GetDoubleListing()
andGetAnotherListing()
calls done in parallel. The overloads forStartNew()
require delegates. As the parameters are not changing, you can make the calls using lambdas like this: