我有以下代码:
Dictionary<string, WSResponse> responseDictionary = new Dictionary<string, WSResponse>();
List<Task> taskList = new List<Task>();
foreach (string ID in IDs)
{
string localID = ID;
Task newTask = Task.Factory.StartNew(() =>
{
WSResponse response = Query.GetListFor(localID);
responseDictionary.Add(localID, response);
});
taskList.Add(newTask);
}
Task.WaitAll(taskList.ToArray());
在这种情况下我应该使用 aConcurrentDictionary
而不是 a吗?Dictionary
即使我确保键不会在逻辑级别上重复?