Whats the advantage of using AsParallel on an array opposed to just using the array directly?
Code:al.ToArray().AsParallel().ForAll(po => CacheToAppFabric((MyObject)po));
Printable View
Whats the advantage of using AsParallel on an array opposed to just using the array directly?
Code:al.ToArray().AsParallel().ForAll(po => CacheToAppFabric((MyObject)po));
Your operations in the ForAll will be parallelized. They will execute in parallel (probably dependent on your machine). That's why it's called "ForAll" and not "ForEach".
Be careful when using AsParallel. Note that while it is thread safe it does not guarantee operations you may perform from within the LINQ statement are thread safe. Calling a method or extension from within the LINQ statement that is not thread safe invalidates the thread safety of it.
AsParallel also does not guarantee your statement will run faster in all cases such as in the case of calling a query operator that has a lock within it. The lock will limit the LINQ statement's parallel efficiency.
http://www.albahari.com/threading/