Blocking until a Thread Finishes

The desktop version of the .NET Framework features a method called Thread.Join(). Given a thread called l_Thread, if another thread calls l_Thread.Join(), then the other thread blocks until l_Thread terminates. The .NET Compact Framework does not support Thread.Join().

One way to wait for another thread to die is to use a busy wait. For example, the thread method might update the Boolean class member m_Alive to false as it exits. Another thread can sit and wait for the first thread to finish by writing code that looks like this:

C#
// Wait for another thread to set m_Alive to false
while (m_Alive)
{
}


VB
' Wait for another thread to set m_Alive to false
while (m_Alive = True)
End While

This would be a very bad ...

Get Microsoft® .NET Compact Framework Kick Start now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.