/// <summary> /// Add a new thread that will run continuously. /// </summary> /// <param name="collector">This will gather data from the main thread (Executed on main thread).</param> /// <param name="handler">This will process the data given by the collector (Executed on subthread).</param> /// <param name="processor">This will put the processed data back on the main thread (Executed on main thread).</param> /// <param name="id">Used to identify thread, used for ending single target threads.</param> public void Add(Func <object> collector, Func <object, object> handler, Action <object> processor, string id) { ThreadPoolable threadPoolable = nonActive.Pop(); threadPoolable.Fill(collector, handler, processor, id); waitList.Add(threadPoolable); }
/// <summary> /// Remove target thread with target id. /// </summary> public void Remove(string id) { Func <ThreadPoolable, bool> action = x => x.ID == id; ThreadPoolable threadPoolable = active.Get(action); threadPoolable.Clear(); active.Remove(threadPoolable); nonActive.Add(threadPoolable); }