Table of Contents

Class ZeroSizeThreadPool

Namespace
Quartz.Impl
Assembly
Quartz.dll

This is class is a simple implementation of a zero size thread pool, based on the IThreadPool interface.

public sealed class ZeroSizeThreadPool : IThreadPool
Inheritance
ZeroSizeThreadPool
Implements
Inherited Members

Remarks

The pool has zero Threads and does not grow or shrink based on demand. Which means it is obviously not useful for most scenarios. When it may be useful is to prevent creating any worker threads at all - which may be desirable for the sole purpose of preserving system resources in the case where the scheduler instance only exists in order to schedule jobs, but which will never execute jobs (e.g. will never have Start() called on it).

Constructors

ZeroSizeThreadPool(ILogger<ZeroSizeThreadPool>?)

Initializes a new instance of the ZeroSizeThreadPool class.

public ZeroSizeThreadPool(ILogger<ZeroSizeThreadPool>? logger = null)

Parameters

logger ILogger<ZeroSizeThreadPool>

Where the pool reports the calls it refuses. Filled in by the container when it builds the pool; a pool constructed by hand is handed nothing and reads LogProvider, as before.

Properties

PoolSize

Gets the size of the pool.

public int PoolSize { get; }

Property Value

int

The size of the pool.

Methods

Initialize(CancellationToken)

Called by the QuartzScheduler before the thread pool is used, in order to give the it a chance to Initialize.

public ValueTask Initialize(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask

Shutdown(bool, CancellationToken)

Called by the QuartzScheduler to inform the thread pool that it should free up all of it's resources because the scheduler is shutting down.

public ValueTask Shutdown(bool waitForJobsToComplete = true, CancellationToken cancellationToken = default)

Parameters

waitForJobsToComplete bool

Ignored: this pool runs nothing, so there is never anything to wait for.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask

TryRun(Func<ValueTask>, CancellationToken)

Execute the given Task in the next available Thread.

public ValueTask<bool> TryRun(Func<ValueTask> action, CancellationToken cancellationToken = default)

Parameters

action Func<ValueTask>

The work to run.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask<bool>

Remarks

The implementation of this interface should not throw exceptions unless there is a serious problem (i.e. a serious misconfiguration). If there are no available threads, rather it should either queue the action, or wait until a thread is available, depending on the desired strategy.

WaitForAvailableThreads(CancellationToken)

Determines the number of threads that are currently available in the pool. Useful for determining the number of times TryRun(Func<ValueTask>, CancellationToken) can be called before returning false.

public ValueTask<int> WaitForAvailableThreads(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask<int>

the number of currently available threads

Remarks

The implementation of this method should wait until there is at least one available thread.