teddy2 - 8 months ago 96
C# Question

# C# Parallel.ForEach, not working

I am trying to convert

ForEach
with a
Parallel.ForEach
.

ForEach
, works perfectly fine and gives the expected result. Where as when I try to use
Parallel.ForEach
, I get an error for the List variable, saying its not available.

What am I doing wrong? I have added comments in the code to explain.

 public  class CalssTest
{

List<AssetDetails> assets;
AssetDetails asset;

{
//Skipped here to keep the code short.
}

private void cmdValidate_Click(object sender, RoutedEventArgs e)
{
OrderManager om = new OrderManager();

using (ATXFunctions atx = new ATXFunctions())
{
//*****THIS WORKS *********//.
{
}

//*****THIS ERRORS OUT *********//.
// Error ::
//The name 'assets' does not exist in the current context

{
});

}
}
}


    Parallel.ForEach(assets , (ad) =>