Multiple Request Processor

K

Karthik D V

Hi All,
I have the following requirement.

I have table which contains requestID, priority and the request
status(status can be 'Queued','Procesing','Completed','Failed')

I need a class which takes 5 top priority requests and process the
same simultaniously, now if any of these requests completed, for the
same slot I should get the next priority requests to process.

How do I do this? I thought og doing using ThreadPool, but in
threadPool we dont have the facility to know whether the given thread
is completed or not :(

Please help me in this regard.

Thank you.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Karthik said:
Hi All,
I have the following requirement.

I have table which contains requestID, priority and the request
status(status can be 'Queued','Procesing','Completed','Failed')

I need a class which takes 5 top priority requests and process the
same simultaniously, now if any of these requests completed, for the
same slot I should get the next priority requests to process.

How do I do this? I thought og doing using ThreadPool, but in
threadPool we dont have the facility to know whether the given thread
is completed or not :(

Please help me in this regard.

Thank you.

Use an array of Thread objects, and monitor the ThreadState property of
them.
 
P

Peter Duniho

Karthik said:
Hi All,
I have the following requirement.

I have table which contains requestID, priority and the request
status(status can be 'Queued','Procesing','Completed','Failed')

I need a class which takes 5 top priority requests and process the
same simultaniously, now if any of these requests completed, for the
same slot I should get the next priority requests to process.

How do I do this? I thought og doing using ThreadPool, but in
threadPool we dont have the facility to know whether the given thread
is completed or not :(

Please help me in this regard.

It seems to me that a simple approach would be to use the
BackgroundWorker class, handle the RunWorkerCompleted event, and in your
handler, start a new BackgroundWorker from your queue of prioritized
requests.

You would initialize the whole thing by starting five BackgroundWorkers
initially, and then only starting a new BackgroundWorker after that in
your RunWorkerCompleted event handler.

If you have the ability to add new requests after processing has
started, then you would want to keep a counter of the active requests
(add one when you start a BackgroundWorker, subtract one in the
RunWorkerCompleted event handler), and allow for a new requests to be
started as it's added if you are under your maximum of five.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top