S
Sudip_inn
Guest
please see my code and tell me how to use Parallel.Foreach for my scenario and my code
//Parallel.ForEach(OrderWiseLineItem, data =>
foreach (var data in OrderWiseLineItem)
{
// string Li = data1.LineItem;
string section = data.Section;
string Li = data.Lineitem;
if (!String.IsNullOrEmpty(Li) && !String.IsNullOrEmpty(section))
{
//Parallel.ForEach(DistinctBroker, broker =>
foreach (var broker in DistinctBroker)
{
//lock (_lock)
//{
// for broker row .... weightage 1 (no color)
rowNumber = rowNumber + 1;
//Interlocked.Increment(ref rowNumber);
brokerRowWeightageRowNumber = new WeightageRowNumber();
brokerRowWeightageRowNumber.Section = section;
brokerRowWeightageRowNumber.Lineitem = Li;
brokerRowWeightageRowNumber.Broker = broker;
brokerRowWeightageRowNumber.RowNumber = rowNumber;
brokerRowWeightageRowNumber.Weightage = (int)RowWeightage.BrokerRow;
//WeightageRowNumberall.Add(brokerRowWeightageRowNumber);
WeightageRowNumberall.Add(brokerRowWeightageRowNumber);
//}
}
//lock (_lock)
//{
// for Consensus row .... weightage 2 (red color)
rowNumber = rowNumber + 1;
//Interlocked.Increment(ref rowNumber);
ConsensusRowWeightageRowNumber = new WeightageRowNumber();
ConsensusRowWeightageRowNumber.Section = section;
ConsensusRowWeightageRowNumber.Lineitem = Li;
ConsensusRowWeightageRowNumber.Broker = "";
ConsensusRowWeightageRowNumber.RowNumber = rowNumber;
ConsensusRowWeightageRowNumber.Weightage = (int)RowWeightage.ConsenSusRow;
//WeightageRowNumberall.Add(ConsensusRowWeightageRowNumber);
WeightageRowNumberall.Add(ConsensusRowWeightageRowNumber);
//liitemsearchdata.Add(Li + "~" + section + "~" + rowNumber.ToString());
//data.Lineitem + "~" + data.Section + "~" + (data.RowNumber + 1).ToString()
//}
if (qcTrueDistin.Any(x => x.TabName.Equals(section) && x.StandardLineItem.Equals(Li)))
{
// for QC Check row .... weightage 3, if any (yellow color)
//Parallel.ForEach(DistinctBroker, broker =>
foreach (var broker in DistinctBroker)
{
//lock (_lock)
//{
//Interlocked.Increment(ref rowNumber);
rowNumber = rowNumber + 1;
QcRowWeightageRowNumber = new WeightageRowNumber();
QcRowWeightageRowNumber.Section = section;
QcRowWeightageRowNumber.Lineitem = Li;
QcRowWeightageRowNumber.Broker = broker;
QcRowWeightageRowNumber.RowNumber = rowNumber;
QcRowWeightageRowNumber.Weightage = (int)RowWeightage.QcRow;
WeightageRowNumberall.Add(QcRowWeightageRowNumber);
//}
}
}
}
}
also tell me how to force parallel foreach to init or assign data order wise ?
i used parallel foreach but getting error in other part of same function. hence my function is too big and that is why i can not paste the whole code rather paste the paralle.foreach part only.
Continue reading...
//Parallel.ForEach(OrderWiseLineItem, data =>
foreach (var data in OrderWiseLineItem)
{
// string Li = data1.LineItem;
string section = data.Section;
string Li = data.Lineitem;
if (!String.IsNullOrEmpty(Li) && !String.IsNullOrEmpty(section))
{
//Parallel.ForEach(DistinctBroker, broker =>
foreach (var broker in DistinctBroker)
{
//lock (_lock)
//{
// for broker row .... weightage 1 (no color)
rowNumber = rowNumber + 1;
//Interlocked.Increment(ref rowNumber);
brokerRowWeightageRowNumber = new WeightageRowNumber();
brokerRowWeightageRowNumber.Section = section;
brokerRowWeightageRowNumber.Lineitem = Li;
brokerRowWeightageRowNumber.Broker = broker;
brokerRowWeightageRowNumber.RowNumber = rowNumber;
brokerRowWeightageRowNumber.Weightage = (int)RowWeightage.BrokerRow;
//WeightageRowNumberall.Add(brokerRowWeightageRowNumber);
WeightageRowNumberall.Add(brokerRowWeightageRowNumber);
//}
}
//lock (_lock)
//{
// for Consensus row .... weightage 2 (red color)
rowNumber = rowNumber + 1;
//Interlocked.Increment(ref rowNumber);
ConsensusRowWeightageRowNumber = new WeightageRowNumber();
ConsensusRowWeightageRowNumber.Section = section;
ConsensusRowWeightageRowNumber.Lineitem = Li;
ConsensusRowWeightageRowNumber.Broker = "";
ConsensusRowWeightageRowNumber.RowNumber = rowNumber;
ConsensusRowWeightageRowNumber.Weightage = (int)RowWeightage.ConsenSusRow;
//WeightageRowNumberall.Add(ConsensusRowWeightageRowNumber);
WeightageRowNumberall.Add(ConsensusRowWeightageRowNumber);
//liitemsearchdata.Add(Li + "~" + section + "~" + rowNumber.ToString());
//data.Lineitem + "~" + data.Section + "~" + (data.RowNumber + 1).ToString()
//}
if (qcTrueDistin.Any(x => x.TabName.Equals(section) && x.StandardLineItem.Equals(Li)))
{
// for QC Check row .... weightage 3, if any (yellow color)
//Parallel.ForEach(DistinctBroker, broker =>
foreach (var broker in DistinctBroker)
{
//lock (_lock)
//{
//Interlocked.Increment(ref rowNumber);
rowNumber = rowNumber + 1;
QcRowWeightageRowNumber = new WeightageRowNumber();
QcRowWeightageRowNumber.Section = section;
QcRowWeightageRowNumber.Lineitem = Li;
QcRowWeightageRowNumber.Broker = broker;
QcRowWeightageRowNumber.RowNumber = rowNumber;
QcRowWeightageRowNumber.Weightage = (int)RowWeightage.QcRow;
WeightageRowNumberall.Add(QcRowWeightageRowNumber);
//}
}
}
}
}
also tell me how to force parallel foreach to init or assign data order wise ?
i used parallel foreach but getting error in other part of same function. hence my function is too big and that is why i can not paste the whole code rather paste the paralle.foreach part only.
Continue reading...