Skip to main content


Showing posts from September, 2012

Multi-Threading with ThreadPool and a Thread Manager

The past few weeks have been spent trying to make some tasks in a winforms app multi-threaded. Threaded applications can get tricky really fast. I needed to create a thread manager that helped me queue and create new threads via the ThreadPool. Here is the solution I came up with. I by no means think is the best or only solution. It in fact has one constraint with it I will call out at the end. It is an approach to doing threading in .Net applications though.I needed a class that would do the following:- Calculate how many threads to spin up- Calculate how much work to give to each thread- Queue new threads with the ThreadPool- Determine if WaitHandles needed to be created for the new threads- Pass the WaitHandles to the new threads so they can signal when complete- Return a collection of created WaitHandles back so future process could wait on all threads if neededFirst I created a ThreadState object to hold the information I needed to pass to each thread. 1: publicclass ThreadSt…