Parallel Foreach loop [on hold]











up vote
-2
down vote

favorite












GetValuesFromDB will fetch values from the DB and return a new object which will have SubStatus.
ProcessCounter is a class that defines SafeCounter for Processed, Passed, Failed and Skipped. The Construction set all of them to 0. scheduler defines the MaxDegreeOfParallelism.
GetValuesFromDB or DbOperation doesn't have any lock keyword.
I don't know what the issue is but some of the 'row' are not processed.



                ProcessCounter result = new ProcessCounter();
ParallelOptions options = new ParallelOptions()
{
TaskScheduler = scheduler
};

Parallel.ForEach(GetValuesFromDB(), options, row =>
{
try
{
if (row != null)
{
int newSubStatus = 0;
int currentSubStatus = row.SubStatus;

switch (currentSubStatus)
{
case 1:
newSubStatus = //service call
break;

case 2:
case 3:
newSubStatus = //service call
break;

case 4:
newSubStatus = //service call
break;

case 5:
newSubStatus = //service call
break;
}

if (newSubStatus > 0 && newSubStatus != currentSubStatus)
{
result.Processed++;
DbOperation(newSubStatus);
result.Passed++;
}
}
}
catch (Exception ex)
{
result.Failed++;
}
});









share|improve this question









New contributor




sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Heslacher, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, πάντα ῥεῖ, t3chb0t 11 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Heslacher, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, πάντα ῥεῖ, t3chb0t

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Heslacher
    12 hours ago















up vote
-2
down vote

favorite












GetValuesFromDB will fetch values from the DB and return a new object which will have SubStatus.
ProcessCounter is a class that defines SafeCounter for Processed, Passed, Failed and Skipped. The Construction set all of them to 0. scheduler defines the MaxDegreeOfParallelism.
GetValuesFromDB or DbOperation doesn't have any lock keyword.
I don't know what the issue is but some of the 'row' are not processed.



                ProcessCounter result = new ProcessCounter();
ParallelOptions options = new ParallelOptions()
{
TaskScheduler = scheduler
};

Parallel.ForEach(GetValuesFromDB(), options, row =>
{
try
{
if (row != null)
{
int newSubStatus = 0;
int currentSubStatus = row.SubStatus;

switch (currentSubStatus)
{
case 1:
newSubStatus = //service call
break;

case 2:
case 3:
newSubStatus = //service call
break;

case 4:
newSubStatus = //service call
break;

case 5:
newSubStatus = //service call
break;
}

if (newSubStatus > 0 && newSubStatus != currentSubStatus)
{
result.Processed++;
DbOperation(newSubStatus);
result.Passed++;
}
}
}
catch (Exception ex)
{
result.Failed++;
}
});









share|improve this question









New contributor




sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Heslacher, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, πάντα ῥεῖ, t3chb0t 11 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Heslacher, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, πάντα ῥεῖ, t3chb0t

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Heslacher
    12 hours ago













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











GetValuesFromDB will fetch values from the DB and return a new object which will have SubStatus.
ProcessCounter is a class that defines SafeCounter for Processed, Passed, Failed and Skipped. The Construction set all of them to 0. scheduler defines the MaxDegreeOfParallelism.
GetValuesFromDB or DbOperation doesn't have any lock keyword.
I don't know what the issue is but some of the 'row' are not processed.



                ProcessCounter result = new ProcessCounter();
ParallelOptions options = new ParallelOptions()
{
TaskScheduler = scheduler
};

Parallel.ForEach(GetValuesFromDB(), options, row =>
{
try
{
if (row != null)
{
int newSubStatus = 0;
int currentSubStatus = row.SubStatus;

switch (currentSubStatus)
{
case 1:
newSubStatus = //service call
break;

case 2:
case 3:
newSubStatus = //service call
break;

case 4:
newSubStatus = //service call
break;

case 5:
newSubStatus = //service call
break;
}

if (newSubStatus > 0 && newSubStatus != currentSubStatus)
{
result.Processed++;
DbOperation(newSubStatus);
result.Passed++;
}
}
}
catch (Exception ex)
{
result.Failed++;
}
});









share|improve this question









New contributor




sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











GetValuesFromDB will fetch values from the DB and return a new object which will have SubStatus.
ProcessCounter is a class that defines SafeCounter for Processed, Passed, Failed and Skipped. The Construction set all of them to 0. scheduler defines the MaxDegreeOfParallelism.
GetValuesFromDB or DbOperation doesn't have any lock keyword.
I don't know what the issue is but some of the 'row' are not processed.



                ProcessCounter result = new ProcessCounter();
ParallelOptions options = new ParallelOptions()
{
TaskScheduler = scheduler
};

Parallel.ForEach(GetValuesFromDB(), options, row =>
{
try
{
if (row != null)
{
int newSubStatus = 0;
int currentSubStatus = row.SubStatus;

switch (currentSubStatus)
{
case 1:
newSubStatus = //service call
break;

case 2:
case 3:
newSubStatus = //service call
break;

case 4:
newSubStatus = //service call
break;

case 5:
newSubStatus = //service call
break;
}

if (newSubStatus > 0 && newSubStatus != currentSubStatus)
{
result.Processed++;
DbOperation(newSubStatus);
result.Passed++;
}
}
}
catch (Exception ex)
{
result.Failed++;
}
});






c# task-parallel-library






share|improve this question









New contributor




sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 12 hours ago





















New contributor




sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 13 hours ago









sam

11




11




New contributor




sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by Heslacher, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, πάντα ῥεῖ, t3chb0t 11 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Heslacher, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, πάντα ῥεῖ, t3chb0t

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by Heslacher, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, πάντα ῥεῖ, t3chb0t 11 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Heslacher, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, πάντα ῥεῖ, t3chb0t

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Heslacher
    12 hours ago














  • 1




    Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
    – Heslacher
    12 hours ago








1




1




Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Heslacher
12 hours ago




Welcome to Code Review. I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
– Heslacher
12 hours ago















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Quarter-circle Tiles

build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

Mont Emei