c# - Separate threadPool for each task -
i've got application has 2 main task: encoding, processing video. these tasks independant. each task run configurable number of threads. reason 1 task use threadpool , setmaxthreads. i've got 2 tasks , "two configurable(number of threads) threapool each task". well, threadpool static class. how can implement strategy(easy configurable number of threads each task).
thanks
you want own thread pool. if using .net 4.0 easy roll own if use blockingcollection
class.
public class customthreadpool { private blockingcollection<action> m_workitems = new blockingcollection<action>(); public customthreadpool(int numberofthreads) { (int = 0; < numberofthreads; i++) { var thread = new thread( () => { while (true) { action action = m_workitems.take(); action(); } }); thread.isbackground = true; thread.start(); } } public void queueuserworkitem(action action) { m_workitems.add(action); } }
that there it. create customthreadpool
each actual pool want control. posted minimum amount of code crude thread pool going. naturally, might want tweak , expand implementation suit specific need.
Comments
Post a Comment