Karthik D V wrote:
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