We have already examined joining a thread in the previous chapter. When you join a thread, you tell the current thread to wait on the thread, which you are joining, to complete. This allows you to coordinate work between two threads.
This was very handy in the example where we wanted to know when one piece is complete before we start the next piece.
For our application, let's say we want to examine how the performance changes if all of the bitmap processing threads run sequentially instead of concurrently.
If we want all of our bitmap processing threads to run sequentially, then right after we start a thread, we will join the thread. This will halt execution of the main thread until the bitmap processing thread we just started has finished. To do this, change the bottom for
loop in the butFindOldStars_Click
event handler and add the following line:
prloThreadList[liThreadNumber].Join();
So, now the for
loop looks like this:
// Now, start the threads ...