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

Popular posts from this blog

javascript - Create websocket without connecting -

how to do line continuation in perl debugger for entering raw multi-line text (EOT)? -

Android SDK Manager freezes after installation of OSX 10.11 El Capitan public Beta -