5
I’m having some problems using parallelism (I don’t have much knowledge in this area) with C# and Entity Framework.
My scenario is as follows, I am using an ASP.NET MVC application and within it I have a list of objects that do various validations. As there are many (more than 45,000 on average) if I wait in a single thread, the delay is great.
For this I thought of working with parallelism, only that I ended up having some problems like dbcontext that I had to instantiate for each thread to be able to work in multiple threads.
I’m using Parallel.Foreach(list, x => Methododevalidation(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 make validations in parallel? Do you have any articles to recommend?
Will this work in the database? Read this: http://answall.com/q/1946/101
– Maniero
Ball show @bigown!
– Kevin Allen