Thread: AsParallel

  1. #1
    Registered User
    Join Date
    Jan 2007


    Whats the advantage of using AsParallel on an array opposed to just using the array directly?

    al.ToArray().AsParallel().ForAll(po => CacheToAppFabric((MyObject)po));

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    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".

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    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.
    Last edited by VirtualAce; 10-03-2012 at 05:40 PM.

Popular pages Recent additions subscribe to a feed