Parallel vs Tasks vs Threads

Asked

Viewed 38 times

1

I was doing a Consoleapp and I was left with a doubt, what is the big difference of each of these and what are the advantages and disadvantages? In which case I would use Parallel, in which case I would use Tasks and in which case I would use Threads.

For you to understand better, I have the following problem, I need to start 4 simultaneous tasks to make separate validations (by the way, the code is already working, but I want to know what would be the best implementation)

My code is like this:

foreach (var lista in listas)
{
    ValidationBSS bss = new ValidationBSS(instanceId, id);
    tasks[listas.IndexOf(lista)] = (Task.Factory.StartNew(() => bss.Validation(lista)));
}

Task.WaitAll(tasks);

Parallel.ForEach(listas, obj => 
{
    ValidationBSS bss = new ValidationBSS(instanceId, id);
    bss.Validation(obj);
} );
  • 1

    See if this answers: http://answall.com/q/123173/101 and http://answall.com/q/157435/101.

  • @bigown responded and helped me a lot, thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.