KiloWatt.Runtime.Support.ThreadPoolComponent.AddTask C# (CSharp) Method

AddTask() public method

Add a task to the thread queue. When a thread is available, it will dequeue this task and run it. Once complete, the task will be marked complete, but your application won't be called back until the next time Update() is called (so that callbacks are from the main thread).
public AddTask ( TaskFunction function, TaskComplete completion, TaskContext ctx ) : System.Threading.Task
function TaskFunction The function to call within the thread.
completion TaskComplete The callback to report results to, or null. If /// you care about which particular task has completed, use a different instance /// for this delegate per task (typically, a delegate on the task itself).
ctx TaskContext A previously allocated TaskContext, to allow for waiting /// on the task, or null. It cannot have been already used.
return System.Threading.Task
        public Task AddTask(TaskFunction function, TaskComplete completion, TaskContext ctx)
        {
            if (function == null)
            throw new System.ArgumentNullException("function");
              Worker w;
              lock (this)
              {
            if (disposed_)
              throw new System.ObjectDisposedException("ParallelThreadPool");
            qDepth_++;
            w = NewWorker(function, completion);
            if (ctx != null)
              ctx.Init(w);
            if (workList_ == null)
              workList_ = w;
            else
              workListEnd_.next_ = w;
            workListEnd_ = w;
              }
              workEvent_.Set();
              return w;
        }