Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if Thread finished execution

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.

like image 550
Bogi Avatar asked May 05 '10 13:05

Bogi


People also ask

How can you tell if a thread is complete C#?

A Thread class is responsible for creating and managing a thread in multi-thread programming. It provides a property known as IsAlive to check if the thread is alive or not. Or in other words, the value of this property indicates the current execution of the thread.

What happens when a thread finishes execution?

Finishing Threads So when does a thread finish? It happens in one of two cases: all instructions in the Runnable are executed. an uncaught exception is thrown from the run method.

What happens to thread pool after it finishes its task?

Once a thread in the thread pool completes its task, it's returned to a queue of waiting threads. From this moment it can be reused. This reuse enables applications to avoid the cost of creating a new thread for each task. There is only one thread pool per process.


1 Answers

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

like image 51
Mohanavel Avatar answered Sep 22 '22 22:09

Mohanavel