m.edmondson
m.edmondson

Reputation: 30872

Parallel.ForEach is not executing the method

I'm attempting to Parallelize the following For Each loop which works as expected. I started with this:

foreach (DataRow drGroup in dsGroups.Tables["Table"].Rows)
         ProduceInvoices(drGroup);

and changed it to:

Parallel.ForEach<DataRow>((IEnumerable<DataRow>)dsGroups.Tables["Table"].Rows, ProduceInvoices)

however ProduceInvoices seem to no longer get executed, despite dsGroup containing rows.

Please can you provide me with any pointers and/or where to look?

Upvotes: 2

Views: 464

Answers (1)

Selman Gen&#231;
Selman Gen&#231;

Reputation: 101681

Try using AsEnumerable method:

Parallel.ForEach<DataRow>(dsGroups.Tables["Table"].AsEnumerable(), ProduceInvoices);

Rows property returns a DataRowCollection which doesn't implement IEnumerable<T>.

Upvotes: 7

Related Questions