ChannelExecutor

Ecng.ComponentModel

Sequential operation executor based on channels. Ensures operations are executed sequentially to prevent file access conflicts.

Erbt von: AsyncDisposable

Implementiert: IChannelExecutorGroup

Konstruktoren

ChannelExecutor
public ChannelExecutor(Action<Exception> errorHandler, TimeSpan flushInterval)
channelExecutor = ChannelExecutor(errorHandler, flushInterval)

Initializes a new instance of the ChannelExecutor.

errorHandler
Error handler for unhandled exceptions.
flushInterval
Interval for batch processing. Use TimeSpan.Zero for immediate execution.

Methoden

Add
public void Add(Func<CancellationToken, ValueTask> action)
channelExecutor.Add(action)

Add async operation to the execution queue.

action
Async operation to execute (receives CancellationToken).
AddAndWaitAsync
public Task AddAndWaitAsync(Func<CancellationToken, ValueTask> action, CancellationToken cancellationToken)
result = channelExecutor.AddAndWaitAsync(action, cancellationToken)

Add async operation to the execution queue and wait for it to complete.

action
Async operation to execute (receives CancellationToken).
cancellationToken
Cancellation token.

Rückgabe: Task that completes when the operation has been executed.

AddAsync
public ValueTask AddAsync(Func<CancellationToken, ValueTask> action, CancellationToken cancellationToken)
result = channelExecutor.AddAsync(action, cancellationToken)

Add async operation to the execution queue asynchronously.

action
Async operation to execute (receives CancellationToken).
cancellationToken
Cancellation token.

Rückgabe: Task.

CreateGroup
public IChannelExecutorGroup CreateGroup(Func<CancellationToken, ValueTask> begin, Func<CancellationToken, ValueTask> end)
result = channelExecutor.CreateGroup(begin, end)

Creates a new operation group with async begin/end callbacks.

begin
Async action called before first operation in the group (receives CancellationToken).
end
Async action called after last operation in the group (always, like finally; receives CancellationToken).

Rückgabe: Group object to add operations to.

DisposeManaged
protected override ValueTask DisposeManaged()
result = channelExecutor.DisposeManaged()

Disposes the managed resources asynchronously. Override this method to add custom clean up of managed resources.

RunAsync
public Task RunAsync(CancellationToken cancellationToken)
result = channelExecutor.RunAsync(cancellationToken)

Starts the channel processor.

cancellationToken
External cancellation token to stop processing.

Rückgabe: Task that completes when processing is stopped.

WaitFlushAsync
public Task WaitFlushAsync(CancellationToken cancellationToken)
result = channelExecutor.WaitFlushAsync(cancellationToken)

Wait for all pending operations to complete.

cancellationToken
Cancellation token.

Rückgabe: Task.