How to check if Thread finished execution

Bogi picture Bogi · May 5, 2010 · Viewed 163.9k times · Source

I have following problem:

I want to check (C#) if a thread has finished execution, i.e. if the thread method has returned. What I do now is call Thread.Join(1), but this gives a 1 ms delay. Is there any way to simply check if a thread has finished. Inspecting Thread.ThreadState just seems too cumbersome.

Answer

Mohanavel picture Mohanavel · May 5, 2010

Use the Thread.IsAlive flag. This is to give the thread status.