Question Threadpool with progress bar

meteorain

New member
Joined
Jul 2, 2009
Messages
1
Programming Experience
1-3
Hi, currently i am using a threadpool that contain a number of thread. This number of thread can be different everytime, sometimes 5, sometimes 10, sometimes 15 and so on (multiple of 5). So now i have it working good by using for loop to queue the thread into threadpool. Now the problems is i do not know how to make the progress bar depending on my threadpool. I want my progress bar to complete only when all the thread are done. After searching google, i found that maybe it can be solve by using AutoResetEvent(false), but after i apply to my program, it still did not work, my program hang at xEvent.WaitOne() method and didnt proceed further, anyone can explain to me how to solve the problem? Or got any other ways? For your information, only 5 threads can be running at the same time as the requirement state so (so i set the setmaxthread to 5 already). Any helps will be appreciate, thanks a lot.
 
I'm not sure how you'd do this, because I'm under the impression that the threadpool exists to perform work that you do not control, or care when it completes; there is a GetAvailableThreads that tells you the number of spare threads; it could be used to work out if any threads in the pool are still active or not, but it's not going to be a concrete way of asserting how far a job is completed. If you only ever use a max of 15 threads, and the GetMaxThreads is 250 by default, then it could work..

Start the threads, start a timer, percent complete = (numThreads -(GetMaxThreads-GetAvailableThreads))/numThreads
 
Back
Top