void ThreadStart (object number)
{
Culture.SetCurrentCulture ();
int OurSleepTime = 0;
int [] numbers = number as int [];
int ThreadNumber = numbers [0];
while (true) {
try {
Action item = null;
if (!queue.TryDequeue (out item)) {
OurSleepTime += m_info.SleepIncrementTime;
if (m_info.KillThreadAfterQueueClear || OurSleepTime > m_info.MaxSleepTime) {
lock (Threads) {
Threads [ThreadNumber] = null;
Interlocked.Decrement (ref nthreads);
break;
}
}
Interlocked.Exchange (ref Sleeping [ThreadNumber], 1);
Interlocked.Increment (ref nSleepingthreads);
try {
Thread.Sleep (OurSleepTime);
} catch (ThreadInterruptedException) {
}
Interlocked.Decrement (ref nSleepingthreads);
Interlocked.Exchange (ref Sleeping [ThreadNumber], 0);
continue;
}
// workers have no business on pool waiting times
// that would make interrelations very hard to debug
// If a worker wants to delay its re-queue, then he should for now sleep before
// asking to be re-queued.
// in future we should add a trigger time delay as parameter to the queue request.
// so to release the thread sooner, like .net and mono can now do.
// This control loop would then have to look for those delayed requests.
// UBIT
OurSleepTime = m_info.InitialSleepTime;
item.Invoke ();
} catch {
}
Thread.Sleep (OurSleepTime);
}
}