Hello friends,
In this article, I will explain to you below details of PLINQ
- What is Parallel LINQ (PLINQ) in C#
- What are the Benefits of PLINQ
- How to Write Parallel LINQ Queries
- What are the methods available in PLINQ
- Performance
- Example
- Parallel execution for a LINQ query by converting it into a PLINQ query.
- WithDegreeOfParallelism(int degreeOfParallelism): Specifies the maximum number of concurrently executing tasks that will be used by the query.
- WithExecutionMode(ParallelExecutionMode mode): Sets the execution mode of the PLINQ query to either ParallelExecutionMode.ForceParallelism or ParallelExecutionMode.Default.
- WithCancellation(CancellationToken cancellationToken): Specifies a cancellation token to enable cancellation of the PLINQ query.
- WithMergeOptions(ParallelMergeOptions options): Sets the merge options for combining results from parallel partitions (e.g., ParallelMergeOptions.NotBuffered or ParallelMergeOptions.AutoBuffered).
- WithOrdered(): Indicates that the output of the query should maintain the original order, even when parallelized.
- WithDegreeOfParallelism(int degreeOfParallelism): Sets the maximum number of concurrently executing tasks used by the query.
- WithExecutionMode(ParallelExecutionMode mode): Specifies the execution mode of the query (ForceParallelism or Default).
- WithCancellation(CancellationToken cancellationToken): Specifies a cancellation token for enabling query cancellation.
- WithMergeOptions(ParallelMergeOptions options): Sets the merge options for combining results from parallel partitions.
- ForAll(Action<TSource> action): Executes the specified action on each element of the query in parallel.
- AsSequential(): Returns a query that ensures subsequent operations are executed sequentially.
- AsUnordered(): Returns an unordered query that may execute more efficiently by ignoring the order of elements.
- Where<TSource>(Func<TSource, bool> predicate): Filters the elements of the query based on a specified condition.
- Select<TSource, TResult>(Func<TSource, TResult> selector): Projects each element of the query into a new form.
- OrderBy<TSource, TKey>(Func<TSource, TKey> keySelector): Sorts the elements of the query in ascending order based on a specified key.
- OrderByDescending<TSource, TKey>(Func<TSource, TKey> keySelector): Sorts the elements of the query in descending order based on a specified key.
- ThenBy<TSource, TKey>(Func<TSource, TKey> keySelector): Performs a secondary ascending sort on the elements based on a specified key.
- ThenByDescending<TSource, TKey>(Func<TSource, TKey> keySelector): Performs a secondary descending sort on the elements based on a specified key.
- GroupBy<TSource, TKey>(Func<TSource, TKey> keySelector): Groups the elements of the query based on a specified key.
- SelectMany<TSource, TResult>(Func<TSource, IEnumerable<TResult>> selector): Projects each element of the query into a sequence and flattens the resulting sequences into one sequence.