Thread.join
-
Hi, I want to understand the concept of the Join method. When I use Thread1.Join() does it mean that Thread1 and the main thread runs simultaneously? If not, I would be happy if you suggest me other method to do it Thank from advance!
Thread.Join has nothing to do with making multiple threads run together - you can think of it as a mechanism where a parent thread can join to child threads and wait until they are finished. It blocks the calling thread and waits for the other threads to finish before it continues processing. So, why would you want to do this? Well, if your parent thread completes processing faster than it's child threads then there would be trouble if the parent thread terminated leaving the child threads running, if those child threads had to access something on the parent thread. There is no mechanism for guaranteeing that two threads will run simultaneously - the OS is responsible for allocating threads, your application must respect the rules given to it. Plus, of course, you can only have two or more threads running together if you've got a multi-core machine.
Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility