Table of Contents

Class SessionProcessRunner<TResult>

Namespace
MVVrus.AspNetCore.ActiveSession.StdRunner
Assembly
MVVrus.AspNetCore.ActiveSession.dll

A class used to create runners that execute background task. The executing task invokes from time to time a callback presented by the runner, informing it about background execution at the time of the invocation.

public class SessionProcessRunner<TResult> : RunnerBase, IDisposable, IRunner<TResult>, IRunner, IAsyncDisposable

Type Parameters

TResult

The type of the result returned by the interface methods of the runner. Values of this type are passed to a callback and a value of this type is optionally returned by a background task.

Inheritance
SessionProcessRunner<TResult>
Implements
IRunner<TResult>
Inherited Members
Extension Methods

Remarks

  1. The callback is a delegate of type Action<TResult, Int32?>, accepting two values: an intermediate result of the background process and an estimation of final Position value after completion of the background task. If this estimation cannot be given the backgrond task should pass null instead of it.
  2. The value of the Position property of runners of this class indicates a number of invocations of the callback was made so far plus one more if the background task has run to completion.
  3. Delegates passed to constructors of this class must accept two parameters: the callback delegate to be periodically invoked (the runner code passes its internal method via this parameter) and a CancellationToken that can be used for cooperative cancellation of the background task (the runner code passes its CompletionToken via this parameter).
  4. Delegates passed to constructors of this class belongs to one of two categories: one that directly creates the background task (i.e. retruns result of type Task or its descendant, see below) and the other that serves as a body of a background task executed synchronously by a thread from the thread pool. The later delegates may return TResult or return nothing.
  5. The runners belonging to this class can deal with two different types of background tasks: one that returns the final result (i.e. having type Task<TResult>) and the other that does not return any result (i.e. having type Task), the result passed by the last callback invoked being assumed as a final one. A type of a delegate passed to the instance constructor determines a type of the background task for the instance created: if the delegate returns Task<TResult> or just TResult then the background task returns a final result, if the delegate returns Task or does not return anything then the background task does not return a final result.
  6. Also there are two sorts of constructors for this class: one that creates instance that uses an internal CancellationTokenSource for its CompletionToken and the other that can accept an external CancellationTokenSource for this purpose (see description of RunnerBase constructor parameters ). The former accepts a delegate as its first parameter while the later accepts as its first parameter a tuple of 3 values: a delegate, a CancellationTokenSource and a bool value indicating passing ownership of the second value.

Constructors

SessionProcessRunner(Action<Action<TResult, int?>, CancellationToken>, RunnerId, ILogger<SessionProcessRunner<TResult>>?)

A constructor that creates an instance of the runner by means of TypeRunnerFactory. An external source for CompletionToken property of the runner cannot be used. The runner will run a background task that executes the specified (synchronous) delegate without returning the final result from the task.

SessionProcessRunner(Func<Action<TResult, int?>, CancellationToken, Task<TResult>>, RunnerId, ILogger<SessionProcessRunner<TResult>>?)

A constructor that creates an instance of the runner by means of TypeRunnerFactory. An external source for CompletionToken property of the runner cannot be used. The runner will run a background task created by the specified delegate returning the final result from the task.

SessionProcessRunner(Func<Action<TResult, int?>, CancellationToken, Task>, RunnerId, ILogger<SessionProcessRunner<TResult>>?)

A constructor that creates an instance of the runner by means of TypeRunnerFactory. An external source for CompletionToken property of the runner cannot be used. The runner will run a background task created by the specified delegate without returning the final result from the task.

SessionProcessRunner(Func<Action<TResult, int?>, CancellationToken, Task>, CancellationTokenSource?, bool, RunnerId, ILogger?)

A constructor that performs real work of creating an instance of the runner of this class. This is a protected constructor that is used by all public constructors of this class and may be used by constructors of descendent classes.

SessionProcessRunner(Func<Action<TResult, int?>, CancellationToken, TResult>, RunnerId, ILogger<SessionProcessRunner<TResult>>?)

A constructor that creates an instance of the runner by means of TypeRunnerFactory. An external source for CompletionToken property of the runner cannot be used. The runner will run a background task that executes the specified (synchronous) delegate returning the final result from the task.

SessionProcessRunner((Action<Action<TResult, int?>, CancellationToken> ProcessTaskBody, CancellationTokenSource? Cts, bool PassCtsOwnership), RunnerId, ILogger<SessionProcessRunner<TResult>>?)

A constructor that creates an instance of the runner by means of TypeRunnerFactory. An external source for CompletionToken property of the runner can be used. The runner will run a background task that executes the specified (synchronous) delegate without returning the final result from the task.

SessionProcessRunner((Func<Action<TResult, int?>, CancellationToken, Task<TResult>> ProcessTaskCreator, CancellationTokenSource? Cts, bool PassCtsOwnership), RunnerId, ILogger<SessionProcessRunner<TResult>>?)

A constructor that creates an instance of the runner by means of TypeRunnerFactory. An external source for CompletionToken property of the runner can be used. The runner will run a background task created by the specified delegate returning the final result from the task.

SessionProcessRunner((Func<Action<TResult, int?>, CancellationToken, Task> ProcessTaskCreator, CancellationTokenSource? Cts, bool PassCtsOwnership), RunnerId, ILogger<SessionProcessRunner<TResult>>?)

A constructor that creates an instance of the runner by means of TypeRunnerFactory. An external source for CompletionToken property of the runner can be used. The runner will run a background task created by the specified delegate without returning the final result from the task.

SessionProcessRunner((Func<Action<TResult, int?>, CancellationToken, TResult> ProcessTaskBody, CancellationTokenSource? Cts, bool PassCtsOwnership), RunnerId, ILogger<SessionProcessRunner<TResult>>?)

A constructor that creates an instance of the runner by means of TypeRunnerFactory. An external source for CompletionToken property of the runner can be used. The runner will run a background task that executes the specified (synchronous) delegate returning the final result from the task.

Properties

IsBackgroundExecutionCompleted

Indicate whether the background operation is completed.

Methods

Dispose(bool)

Protected, overrides RunnerBase.Dispose(bool), sealed. This method performs a real work of disposing the object instance (synchronously).

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

DisposeAsyncCore()

Protected virtual. This method performs a real work of disposing the object instance asynchronously.

GetAvailable(int, int, string?)

Returns a result of the runner available at the moment of the method call.

GetProgress()

Returns information about progress of background operation of a runner.

GetRequiredAsync(int, CancellationToken, int, string?)

Asynchronously fetch result from the runner up to the specified point.

PreDispose()

Protected, overrides RunnerBase.PreDispose(). Performs preliminary tasks before beginning of disposing any members of any descendent class.

StartBackgroundExecution()

Protected, overrides StartBackgroundExecution() This method is used to start background execution synchronously.