thread-state

Terminated Thread Revival

本秂侑毒 提交于 2019-12-02 01:02:46
I am storing a bunch of threads objects in an arraylist. I want to be able to start these threads at random. Same thread can be started more than once. Before I start a thread object, I check on whether the thread is alive, and if they have either of NEW or TERMINATED status. This restriction because, I don't want to disturb the 'busy' threads. Now, for NEW threads, this works fine. But for TERMINATED thread, I get an exception. When a thread ends, shouldn't it go back to being 'new'? Or are threads 'disposable' - like use once and done? As it says in the documentation for Thread.start() , "It

Thread.IsAlive and Thread.ThreadState==ThreadState.Running

这一生的挚爱 提交于 2019-12-01 16:16:54
I am using to check the condition of a thread with if(Thread.IsAlive) . A form is running in this thread. At times during execution, even though the form remains open, the call to Thread.IsAlive seems to be evaluating to false. I thought to perform the same check with if(Thread.ThreadState==ThreadState.Running) . Is it the right way to do? If not, what is the possible work around? msdn Thread.IsAlive Property true if this thread has been started and has not terminated normally or aborted; otherwise, false. msdn Thread.ThreadState Running The thread has been started, it is not blocked, and

How to check if Thread finished execution

半城伤御伤魂 提交于 2019-11-27 07:58:41
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. Mohanavel Use the Thread.IsAlive flag. This is to give the thread status. You could fire an event from your thread when it finishes and subscribe to that. Alternatively you can call Thread.Join() without any arguments: Blocks the calling thread until a thread terminates, while continuing to

How to check if Thread finished execution

て烟熏妆下的殇ゞ 提交于 2019-11-26 11:08:54
问题 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. 回答1: Use the Thread.IsAlive flag. This is to give the thread status. 回答2: You could fire an event from your thread when it finishes and subscribe to that. Alternatively you can call Thread