0

I want to convert one object (B) to another object(A) type and fill some of the properties of A with some values based on some pre-defined conditions not related to Object B. I have used Convert-all method. It works. But, my question here is how do i use parallel programming or will it make sense using parallel for-each conversion. Other than aggregate or calculation, what are all the real time scenarios we can go for parallel programming in case of Asp.net MVC 4 application.

2 Answers2

0

Are you looking to solve a problem or are your looking for ways to use Parallel programming? If you have much CPU bound work to do, using Parallel.ForEach for example could help. If it is primarily IO bound work use async/await if possible.

See Should I always use Parallel.Foreach because more threads MUST speed up everything? for more thought about parallelism.

Working with parallelism and/or multithreading comes at a cost and increases complexity. In case of object conversion don't overcomplicate things with TPL, use it wisely.

Community
  • 1
  • 1
Peter Bons
  • 26,826
  • 4
  • 50
  • 74
0

The closest parallel equivalent to ConvertAll() would be Parallel LINQ:

var as = bs.AsParallel().Select(b => ConvertBToA(b)).ToList();

Note that even when your code is parallelizable, making it run in parallel may not increase performance, because parallelization has some overhead. This means that the above code makes sense only when executing the ConvertBToA method above takes a relatively long time.

This is especially true for ASP.NET, because there you usually have many requests running in parallel, so speeding up one request by using several CPU cores will also slow down other requests.

what are all the real time scenarios we can go for parallel programming in case of Asp.net MVC 4 application

I think this question is way too broad for Stack Overflow.

svick
  • 236,525
  • 50
  • 385
  • 514