c# - Can I use a normal foreach on a ConcurrentBag? -


in parallel section of code, save results each thread concurrentbag. however, when complete, need iterate through each of these results , run them through evaluation algorithm. normal foreach iterate through members, or need special code? i've thought using queue instead of bag, don't know best. bag typically contain 20 or items @ end of parallel code.

ie, access , run foreach members of concurrentbag?

concurrentbag futures = new concurrentbag(); foreach(move in futures) {  // stuff } 

you don't need special code, c#'s foreach call "getenumerator" which gives snapshot:

the items enumerated represent moment-in-time snapshot of contents of bag. not reflect update collection after getenumerator called.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -