I'm having some problems using parallelism (I'm not very knowledgeable in this area) with C # and Entity Framework.
My scenario is as follows, I'm using an ASP.NET MVC application and inside it I have a list of objects that I do several validations. As there are many (over 45 thousand on average) if I wait in a single thread, the delay is great.
For this I thought of working with parallelism, but I ended up having some problems like dbcontext that I had to instantiate for each thread in order to work on multiple threads.
I'm using Parallel.ForEach (list, x => Validation Method (x) .Wait ()); to perform the validations asynchronously.
Below my validation method.
public Task MetodoDeValidacao(IEnumerable<Lista> lista) {
return Task.Factory.StartNew(() =>
{
if (!_service.fazAlgumaCoisa(lista))
ModelState.AddModelError("Model", "Você não fez alguma coisa");
}
}
My question is: Is this the best way to do parallel validations? Do you have any articles to recommend?