Search code examples
c#multithreadingjoindetach

Thread Detach / Joinable Methods


Where are the C# Thread Detach / Joinable functions?

In C++ 11 these functions are available:

thread::joinable()
thread::detach()

But they can't be found in .NET - where are they?


Solution

  • What would detach do in your mind in .NET? .NET has no automatic storage duration. This concept does not apply.

    joinable doesn't really apply either because you can Join any thread, even Thread.Current. If you insist on C++ semantics:

    Thread someThread = ...;
    bool isJoinable = Thread.Current != someThread;
    

    Thread objects are subject to Garbage Collection but a thread runs to completion regardless of whether the Thread object is still reachable. Don't worry about this.