Run a batch of processes and report progress from each of them?

We have a similar issue with generating reports in a service where dozens of long running reports could be requested simultaneously. The way that we handle resource consumption is that we spin each report off into its own thread, but limit the maximum number of executing threads to a set number.

We have a similar issue with generating reports in a service where dozens of long running reports could be requested simultaneously. The way that we handle resource consumption is that we spin each report off into its own thread, but limit the maximum number of executing threads to a set number. Each thread that is spawned is recorded in a dictionary variable using a key assigned to the thread at the time it is spawned.

The main control process performs continuous loops (sleeping for perhaps 100ms per loop) and checks each of the running threads for completion on each pass. As soon as a thread is identified as having completed, it is removed from the dictionary and the next one in the queue is spawned into a new thread. Because the list of executing threads is always available, we can handle early termination requests and other unusual activities gracefully.

If we needed to provide process to the users, it would be very easy to embed in the activity flow. As a point of reference, the reporting threads that are spawned are actually classes that contain the Thread object that they are executing on. This allows us to control the Thread or provide feedback to the parent process without jumping through a lot of hoops (just make sure that you synclock any resources that are accessed from both outside and inside the thread).

I decided to use the ThreadPool. It literally does the job for me. View Michael's answer.

– Shimmy Nov 3 at 1:10.

1. And 2. I would highly recommend that you look at How to: Use a Thread Pool (C# and Visual Basic) on MSDN.

Especially the ThreadPoolExample-class - it has the solution for your problem 3. If you mean 'continue encrypting after the View/VM is closed': Create the TreadPool-handling in a static class.

Response on 3 - no - it's never ever supposed to convert after the VM is closed. I just want to make sure that when the VM is down (or even further more - the item is removed from the list), it should dispose the underlying wrapper->process), basically I need to know have more control on the VM, I think it's a separate question which is "How to dispose a VM with Prism", I'm sure I'll find some info on Google. Thanks.

– Shimmy Nov 2 at 2:33 Please take a look at this post. Are you sure I should use the ThreadPool? I would really love to, the question is if it's a good idea.

– Shimmy Nov 3 at 1:37.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions