I have the following code:
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());
Should I be using a ConcurrentDictionary
instead of a Dictionary
in this case? Even if I make sure keys do not repeate on the logical level?