I need to modify the below code to use a parallel.foreach
loop vs a regular foreach loop.
The issue that I have is passing an object to to the foreach loop. I am new using parallel.foreach
loop - does anyone have some info on this?
Current code
var objSellerPeramaterValuesList = objInboundDB.GetMwsRequestParameters();
foreach (SellerModel objSellerPeramaterValues in objSellerPeramaterValuesList)
{
Method.InsertProcessLog(new ProcessLogModel
{
sProcessName = sProcessName,
sSellerID = objSellerPeramaterValues.sSellerId,
sStartDate = sProcessStartDate,
sEndDate = sProcessEndDate,
sStatus = "STARTED",
sMessage = "Started Process For ID .. " + objSellerPeramaterValues.sSellerId
});
// more code here......
}
The issue with this is that the list will contain 3000+ items and the loop will loop through each item, I need to run them all in parallel.
So I want to use the Parallel.foreach
function but I can't get it to work by passing the object.