private void RequestWorker() { _pool.QueueUserWorkItem(() => { // this thread is now available for inlining _currentThreadIsRunningTasks = true; try { // Process all available items in the queue. while (true) { Task item; lock (_tasks) { // done processing if (_tasks.Count == 0) { ReleaseWorker(); break; } // Get the next item from the queue item = _tasks.First.Value; _tasks.RemoveFirst(); } // Execute the task we pulled out of the queue TryExecuteTask(item); } } // We're done processing items on the current thread finally { _currentThreadIsRunningTasks = false; } }); }