Thread.Join returns us if the thread has completed. The same we can determine using ThreadState. Then what is the difference between Thread.Join() and Thread.ThreadState?
Can we use them interchangeably?
The difference between Join and looking at ThreadState
manually is that Join
is a blocking operation. The function won't return until the timeout is reached or the target Thread
completes. Checking the ThreadState
is more of a peeking operation.
Thread.join WAITS for the thread to complete. ThreadState just gives you a snapshot of the thread and returns without waiting. There's also a variant of Thread.join that takes a time to wait. ThreadState and Join are extremely different and I don't think both can be used interchangeably.
Try doing a test where you do both calls on a thread that has an infinite loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With