queue - How to set max number of threads running concurrently using ThreadPool in .NET -


i need execute fixed number of threads,say 5, in parallel, , en-queue remaining threads. here piece of code tried.

threadpool.setmaxthreads(5, 0);  threadpool.queueuserworkitem(new waitcallback(threadproc), task1);             thread.sleep(1000);//'threadproc' callback function 

now, when i'm trying run, 7 threads in parallel running threads simultaneously instead of running 5 thread , queuing next 2 threads. how achieve this?

if can use parallel for/foreach have paralleloptions.maxdegreeofparallelism limit number of concurrent operations.


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -