Table of Contents

AsyncWorkloadOptions Class

Definition

Namespace
Cuemon.Threading
Assemblies
Cuemon.Threading.dll
Source
src/Cuemon.Threading/AsyncWorkloadOptions.cs

Configuration options for ParallelFactory.

public class AsyncWorkloadOptions : AsyncOptions, IAsyncOptions, IParameterObject
Inheritance
object
AsyncWorkloadOptions
Implements
Derived
Inherited Members

Examples

The following example demonstrates how to configure AsyncWorkloadOptions to control the partition size when processing items in parallel with AdvancedParallelFactory.ForAsync.

using System;
using System.Threading;
using System.Threading.Tasks;
using Cuemon;
using Cuemon.Threading;

namespace MyApp.Examples;

public class AsyncWorkloadOptionsExample
{
    public async Task DemonstrateAsync()
    {
        // Direct instantiation of AsyncWorkloadOptions
        var workloadOptions = new AsyncWorkloadOptions
        {
            PartitionSize = 4
        };

        var rules = new ForLoopRuleset<int>(0, 20, 1);

        await AdvancedParallelFactory.ForAsync(rules, (i, ct) =>
        {
            Console.WriteLine($"Processing item {i}");
            return Task.CompletedTask;
        }, o =>
        {
            o.PartitionSize = 4;
        });

}
}

Constructors

Name Description
AsyncWorkloadOptions()

Initializes a new instance of the AsyncWorkloadOptions class.

Properties

Name Description
PartitionSize

Gets or sets the size of the partition to allocate work to a set of tasks.