Extensions

ParallelProcessToDictionary (DataTable)

This extension method processes a DataTable in parallel and returns a ConcurrentDictionary containing the results, with the keys generated by the provided callback.

Example:

DataTable dataTable = GetDataTable();
ConcurrentDictionary<int, DataRow> resultDictionary = dataTable.ParallelProcessToDictionary(row => (int)row["Id"]);

ParallelProcessToDictionary (IEnumerable)

This extension method processes an IEnumerable in parallel and returns a ConcurrentDictionary containing the results, with the keys generated by the provided callback.

Example:

IEnumerable<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
ConcurrentDictionary<int, int> resultDictionary = numbers.ParallelProcessToDictionary(number => new KeyValuePair<int, int>(number, number * 2));

ParallelProcessToGroupProcessor

This extension method processes an IEnumerable in parallel to a new grouped processor.

Example:

IEnumerable<MyClass> myClasses = GetMyClasses();

GroupProcessor<MyClass, string> groupProcessor = myClasses.ParallelProcessToGroupProcessor((x) => x.groupByField);

ParallelProcessToSingleProcessor

Converts an IEnumerable to a SingleProcessor using a provided callback function.

Example:

IEnumerable<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
Expression<Func<int, int>> callback = x => x * 2;

SingleProcessor<int, int> singleProcessor = numbers.ParallelProcessToSingleProcessor(callback);

ParallelProcessToBag

This extension method processes an IEnumerable in parallel and returns a ConcurrentBag containing the transformed items, with the transformation function provided by the callback.

Example:

IEnumerable<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
ConcurrentBag<string> resultBag = numbers.ParallelProcessToBag(number => $"Number: {number}");

ParallelProcessToBag (DataTable)

This extension method processes a DataTable in parallel and returns a ConcurrentBag containing the transformed items, with the transformation function provided by the callback.

Example:

DataTable dataTable = GetDataTable();
ConcurrentBag<int> resultBag = dataTable .ParallelProcessToBag(row => (int)row["Id"]);

ParallelProcessToBag (with ExceptionRows)

This extension method processes an IEnumerable in parallel, returns a ConcurrentBag containing the transformed items, and handles exceptions using the provided callback.

Example:

IEnumerable<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
ConcurrentBag<string> resultBag = numbers.ParallelProcessToBag(
    number => $"Number: {number}",
    exceptions => {
        foreach (var exception in exceptions)
        {
            Console.WriteLine($"Error: {exception.exception.Message}, Item: {exception.Item}");
        }
    });

ParallelProcess (ConcurrentBag)

This extension method processes a ConcurrentBag in parallel, invoking the provided callback for each item.

Example:

ConcurrentBag<int> numbers = new ConcurrentBag<int>(new List<int> { 1, 2, 3, 4, 5 });
numbers.ParallelProcess(number => Console.WriteLine($"Processing number: {number}"));

ParallelProcess (ConcurrentDictionary)

This extension method processes a ConcurrentDictionary in parallel, invoking the provided callback for each key-value pair.

Example:

ConcurrentDictionary<int, string> dictionary = new ConcurrentDictionary<int, string>();
dictionary[1] = "One";
dictionary[2] = "Two";
dictionary[3] = "Three";
dictionary.ParallelProcess(pair => Console.WriteLine($"Processing pair: {pair.Key}, {pair.Value}"));

Last updated