How can I convert a foreach to Parallel.ForEach?
17,719
You can do:
Parallel.ForEach(delegates, handler =>
{
//your stuff
});
Consider the following example
List<string> list = new List<string>()
{
"ABC",
"DEF",
"EFG"
};
Parallel.ForEach(list, str =>
{
Console.WriteLine(str);
});
You may also see: How to: Write a Simple Parallel.ForEach Loop
Author by
persianLife
Updated on June 05, 2022Comments
-
persianLife almost 2 years
how to convert:
foreach ( NotifyCollectionChangedEventHandler handler in delegates) { ... }
To somthing like This
Parallel.ForEach( NotifyCollectionChangedEventHandler handler in delegates) { ... }
-
Chris Schiffhauer about 10 yearsWon't the
Bitmap
object leak memory on each iteration?