2

The objects of type FileStream or DB handles have to be properly closed as it use Windows handles internally. Likewise, Threads also use Windows handles right? Does thread has some internal mechanisms to release those Windows handles?

Prasanna
  • 760
  • 2
  • 6
  • 16
  • 1
    file streams and database connections and commands ought to be *disposed*. Disposal and GC are not the same thing. And no, threads don't need to be dispoed. – Damien_The_Unbeliever Jan 30 '14 at 07:13

1 Answers1

2

Thread does not implement IDisposable so it can't be disposed unlike Stream or DB related objects.

Runtime takes care of necessary cleanup of related native object when thread's code finishes execution and GC will normally take care of managed Thread object similarly to other finalizable objects.

Note that there is no direct consistent relationship between OS and managed threads Getting the thread ID from a thread.

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • On a side note, I've been always [curious](http://stackoverflow.com/q/18436409/1768303) if there is any existing CLR host where there is no 1:1 mapping between managed and unmanaged threads. – noseratio Jan 30 '14 at 07:52
  • @Noseratio I don't know - never needed to go that deep. – Alexei Levenkov Jan 30 '14 at 07:56