public bool Enqueue(WorkItem workItem) { // A work item cannot be null, since null is used in the // WaitForWorkItem() method to indicate timeout or cancel if (null == workItem) { throw new ArgumentNullException("taskInfo", "taskInfo cannot be null"); } ValidateNotDisposed(); _tasks.Enqueue(workItem); return true; }
protected virtual object Invoke(TaskStartInfo startInfo, params object[] args) { if (State == TaskState.Completed || State == TaskState.Canceled || State == TaskState.Idea) { if (this.workItem != null) workItem.Dispose(); this.workItem = new WorkItem(func, args); this.workItem.Task = this; this.workItem.Initialize(); this.startInfo = startInfo; this.startInfo.task = this; TaskPool.Queue(this); return workItem.Result; } else { throw new WorkItemInvokeException("state"); } }