Parallel ForEach on DataTable

前端 未结 5 1129
北荒
北荒 2020-12-04 19:27

I would like to use the new Parallel.ForEach function to loop through a datatable and perform actions on each row. I am trying to convert the code below:

           


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 19:39

    Parallel.ForEach() expects the first argument to be an IEnumerable<> type. DataTable.Rows is not, but you can turn it into one with the AsEnumerable() extension method. Try:

    ... Parallel.ForEach(dt.AsEnumerable(), drow => ...
    

提交回复
热议问题