void WorkerMethodWrapper ()
{
int sleepTime = 0;
// Main loop
while (started == 1) {
bool result = false;
try {
result = WorkerMethod ();
} catch (Exception e) {
Console.WriteLine (e.ToString ());
}
// Wait a little and if the Thread has been more sleeping than working shut it down
wait.SpinOnce ();
if (result)
sleepTime = 0;
if (sleepTime++ > sleepThreshold)
break;
}
started = 0;
}