Class AsyncWorkloadOptions
Configuration options for ParallelFactory.
public class AsyncWorkloadOptions : AsyncOptions, IAsyncOptions, IParameterObject
- Inheritance
-
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
AsyncWorkloadOptions()
Initializes a new instance of the AsyncWorkloadOptions class.
public AsyncWorkloadOptions()
Remarks
The following table shows the initial property values for an instance of AsyncWorkloadOptions.
| Property | Initial Value |
|---|---|
| PartitionSize | 2 x ProcessorCount |
Properties
PartitionSize
Gets or sets the size of the partition to allocate work to a set of tasks.
public int PartitionSize { get; set; }
Property Value
- int
The size of the partition to allocate work to a set of tasks.