Code: Select all
//new method
public void IncreaseWorkers(int newWorkerCount)
{
//return if new count is same or less than old count
if (newWorkerCount <= Workers)
return;
lock (_threadLocker)
{
//return if stopped flag is raised
if (Thread.VolatileRead(ref _stopped) == 1)
return;
//get the previous count of workers
var workers = Workers;
//resize workers array to accommodate new threads
System.Array.Resize(ref _workers, newWorkerCount);
// Create and start a separate thread for each new worker
for (int i = workers; i < newWorkerCount; i++)
{
var thread = new Thread(Consume);
_workers[i] = thread;
thread.Start();
}
}
}
Code: Select all
//new method
internal void IncreaseWorkerThreads()
{
_receiveQueue.IncreaseWorkers(WorkerThreads);
}
Code: Select all
...
//get the initial WorkerThreads value
var workerThreads = this.WorkerThreads;
if (evBind != null)
...
if (data.Response != null && data.Response.Status == Common.CommandStatus.ESME_ROK)
{
//if the WorkerThreads value has increased, call the new method
if (this.WorkerThreads > workerThreads)
IncreaseWorkerThreads();
...