c# - parallel.foreach and dictionary collection -
i don't understand how code went wrong here's code piece:
var filter=new dictionary<string,dictionary<string,bool>>(); //data here of type dictionary<string,bool> parallel.foreach(data,t=> { var filter1=data.where(p=>p.value).todictionary(p=>p.key,p=>p.value); filter.add(t.key,filter1); });
sometimes, final filter has null key in has never happened if had used simple loop.
[this] has never happened if had used simple loop.
the problem adding filter
concurrently. fix using asparallel()
:
var filter = data.asparallel().todictionary(t => t.key , data.where(p=>p.value).todictionary(p=>p.key, p=>p.value) );
Comments
Post a Comment