static public void RunTask() { if (numRunningTasks < maxRunningTasks && tasks.Count > 0) { ThreadTask t = tasks.Dequeue(); ThreadPool.QueueUserWorkItem( new WaitCallback(delegate(object ob) { t.RunTask(); }), null); t.StartCoroutine(t.WaitForCallback()); } }