4.13. Know When a Thread Finishes

Problem

You need to know when a thread has finished.

Solution

Use the IsAlive property or the Join method of the Thread class.

How It Works

The easiest way to test whether a thread has finished executing is to test the Thread. IsAlive property. The IsAlive property returns True if the thread has been started but has not terminated or been aborted. The IsAlive property provides a simple test to see whether a thread has finished executing, but commonly you will need one thread to wait for another thread to complete its processing. Instead of testing IsAlive in a loop, which is inefficient, you can use the Thread.Join method.

Join causes the calling thread to block until the referenced thread terminates, at which ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.