Task<string>[] tableOfWebClientTasks = new Task<string>[taskCount];
for (int i = 0; i < taskCount; i++)
{
tableOfWebClientTasks[i] = new WebClient().DownloadStringTask(allUrls[count - i - 1]);
}
Task.Factory.ContinueWhenAll(tableOfWebClientTasks, tasks =>
{
Parallel.ForEach(tasks, task =>
{
//Here I have result from each task.
//But information which url is executed on this task, is lost.
});
});
例如,我可以创建类(具有两个公共属性,一个用于任务,第二个用于 url)并返回实例。但是这种方法我与其他方法联系在一起。
你有解决这个问题的办法吗?