Table of Contents

Class MyThreadPool

Namespace
SunamoThreading
Assembly
SunamoThreading.dll

Implements a simple thread pool that allows dynamic change of the number of working threads. Pool size is not fixed and can have more elements than the configured pool size.

public class MyThreadPool : IThreadPool
Inheritance
MyThreadPool
Implements
Inherited Members
Extension Methods

Properties

ActualPoolSize

Gets the actual number of threads in the pool. It might not equal PoolSize when the number of threads is stabilizing after a pool size change.

public int ActualPoolSize { get; }

Property Value

int

PoolSize

Gets the most recently set size of the pool.

public int PoolSize { get; }

Property Value

int

Methods

QueueUserWorkItem(WaitCallback)

Adds a work item to the job queue and signals waiting threads.

public bool QueueUserWorkItem(WaitCallback callBack)

Parameters

callBack WaitCallback

The callback method to be queued for execution.

Returns

bool

True if the work item was successfully queued.

SetPoolSize(int)

Sets the pool size. After reducing the number of working threads, currently working threads are allowed to finish their jobs (they are not interrupted).

public bool SetPoolSize(int size)

Parameters

size int

The desired number of threads in the pool.

Returns

bool

True if the pool size was successfully updated.