public ThreadTask Add(ParameterizedThreadStart threadStart, object obj) { ThreadTask item = new ThreadTask(obj, threadStart); AddTask(item); return(item); }
public ThreadTask Add(ThreadStart threadStart) { ThreadTask item = new ThreadTask(threadStart); AddTask(item); return(item); }
protected void ExecuteTask(object item) { ThreadTask task = item as ThreadTask; try { task.Execute(); } catch (Exception exception) { task.Exception = exception; } finally { lock (SyncRoot) { _runTasks--; if (AllTasks == 0) { _allTaskCompleted.Set(); } else { TryBeginWaitTask(); } } } }
protected void BeginTask(ThreadTask item) { if (UseSystemThreadPool) { BeginTaskBySystemThreadPool(item); } else { BeginTaskByPersonalThread(item); } _runTasks++; }
public void AddTask(ThreadTask item) { lock (SyncRoot) { if (HasFreeThreads) { BeginTask(item); } else { _queue.Enqueue(item); } _allTaskCompleted.Reset(); } }
protected void BeginTaskByPersonalThread(ThreadTask item) { var thread = new Thread(ExecuteTask); thread.Start(item); }
protected void BeginTaskBySystemThreadPool(ThreadTask item) { ThreadPool.QueueUserWorkItem(ExecuteTask, item); }