In the below code am using Parallel.ForEach
to get the data of each item in my collection and store the response in the dictionary. But, in the dictionary the key and values are mismatched. Response of 1st item, is stored in the name of 2nd Item or 3rd item name.
Dictionary<string, object> keyValues = new Dictionary<string, object>();
Parallel.ForEach(myCollection, item =>
{
var data = GetData(item);
if (!keyValues.ContainsKey(item))
{
keyValues.Add(item, data);
}
});
return keyValues;