Naanou.Common
Class WorkPool

A nicer Thread Pooler. The inbuilt .NET pooler is prone to being swamped by lots of work requests. This one handles things a bit better.

Field Summary
System.Threading.Thread maintainThread
int maxWorkerAgeMins
System.Threading.ManualResetEvent mre
int poolMaxSize
         Maximum number of worker threads used
System.Threading.ManualResetEvent poolMRE
System.Collections.Queue queue
int threadsInUse
         Use tiuLock for access
System.Threading.ReaderWriterLock tiuLock

Constructor Summary
WorkPool()
        Initializes a new instance of the WorkPool class.
WorkPool(int poolSize)
         Constructor

Method Summary
int Cancel(Naanou.Common.IWorkItem item, int removedCount)
         Cancels a work item
void Queue(Naanou.Common.IWorkItem item)
         Queues a work item
void SignalDone(Naanou.Common.WorkPool.WorkerThread t)
         Signal that worker is complete
void Start()
         Starts the dispatcher running
void StartImpl()
         Starts pool management

Methods inherited from class System.Object
Equals, Finalize, GetHashCode, GetType, MemberwiseClone, ToString


Field Detail

maintainThread

protected System.Threading.Thread maintainThread


maxWorkerAgeMins

protected int maxWorkerAgeMins


mre

protected System.Threading.ManualResetEvent mre


poolMaxSize

protected int poolMaxSize

Maximum number of worker threads used


poolMRE

protected System.Threading.ManualResetEvent poolMRE


queue

protected System.Collections.Queue queue


threadsInUse

protected int threadsInUse

Use tiuLock for access


tiuLock

protected System.Threading.ReaderWriterLock tiuLock

Constructor Detail

WorkPool

public WorkPool()

Initializes a new instance of the WorkPool class.


WorkPool

public WorkPool(int poolSize)

Constructor

Method Detail

Cancel

public int Cancel(Naanou.Common.IWorkItem item,
                  int removedCount)

Cancels a work item

Parameters:
item -
found -
Returns:

Queue

public void Queue(Naanou.Common.IWorkItem item)

Queues a work item

Parameters:
item - Item

SignalDone

private void SignalDone(Naanou.Common.WorkPool.WorkerThread t)

Signal that worker is complete

Parameters:
t - Worker

Start

private void Start()

Starts the dispatcher running

Throws:
System.InvalidOperationException - Already running

StartImpl

private void StartImpl()

Starts pool management