/// <summary> /// 得到一个闲置的线程,执行传入的任务,如果没有可用的线程则将其加入一个等待队列 /// </summary> /// <param name="action"></param> /// <param name="arg"></param> /// <returns></returns> public void StartTask(Action <object> action, object arg) { if (threadPool.Count < processorCount) { ThreadRequest request = new ThreadRequest(); request.StartThread(action, arg); threadPool.Add(request); } else { if (unusedThreadStack.Count > 0) { ThreadRequest request = unusedThreadStack.Pop(); request.StartThread(action, arg); } else { VoidTask voidTask = new VoidTask(); voidTask.task = action; voidTask.arg = arg; waitingVoidTasks.Enqueue(voidTask); } } }
public CustomTask(VoidTask vTask, TaskMetaData TaskMetaData) { voidTask = vTask; this.taskMetaData = TaskMetaData; }