.net - C# queueing dependant tasks to be processed by a thread pool -


i want queue dependant tasks across several flows need processed in order (in each flow). flows can processed in parallel.

to specific, let's need 2 queues , want tasks in each queue processed in order. here sample pseudocode illustrate desired behavior:

queue1_workitem wi1a=...;  enqueue wi1a;  ... time passes ...  queue1_workitem wi1b=...;  enqueue wi1b; // must processed after processing of item wi1a complete  ... time passes ...  queue2_workitem wi2a=...;  enqueue wi2a; // can processed concurrently wi1a/wi1b  ... time passes ...  queue1_workitem wi1c=...;  enqueue wi1c; // must processed after processing of item wi1b complete 

here diagram arrows illustrating dependencies between work items:

enter image description here

the question how do using c# 4.0/.net 4.0? right have 2 worker threads, 1 per queue , use blockingcollection<> each queue. instead leverage .net thread pool , have worker threads process items concurrently (across flows), serially within flow. in other words able indicate example wi1b depends on completion of wi1a, without having track completion , remember wi1a, when wi1b arrives. in other words, want say, "i want submit work item queue1, processed serially other items have submitted queue1, possibly in parallel work items submitted other queues".

i hope description made sense. if not please feel free ask questions in comments , update question accordingly.

thanks reading.

update:

to summarize "flawed" solutions far, here solutions answers section cannot use , reason(s) why cannot use them:

tpl tasks require specifying antecedent task continuewith(). not want maintain knowledge of each queue's antecedent task when submitting new task.

tdf actionblocks looked promising, appear items posted actionblock processed in parallel. need items particular queue processed serially.

update 2:

re: actionblocks

it appear setting maxdegreeofparallelism option 1 prevents parallel processing of work items submitted single actionblock. therefore seems having actionblock per queue solves problem disadvantage being requires installation , deployment of tdf library microsoft , hoping pure .net 4.0 solution. far, candidate accepted answer, unless can figure out way pure .net 4.0 solution doesn't degenerate worker thread per queue (which using).

i understand have many queues , don't want tie threads. have actionblock per queue. actionblock automates of need: processes work items serially, , starts task when work pending. when no work pending, no task/thread blocked.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -