0

I have a program in which even though the call stack has been processed fully it shows <Not Available> (like this). So I started debugging froze all other threads and ran the thread completely to find out that with an empty call stack it remained there and showed <Not Available> in the thread window of Visual Studio.

  • So my first question, what exactly is the lifetime of a managed thread (not thread object which is processed by Garbage Collection)?

  • My second question is how can I get this thread to be destroyed (AKA to garbage collection for objects). Tried GC.collect(), but apparently the garbage collector doesn't process CLR implemented managed threads.

Note I have gone through

  • Thread Object Lifetime( <- Thread Object, not thread), and
  • Killing Thread ( <- Killing or terminating a running thread, I am interested for an already finished thread, with an empty call stack), and a number of similar others...

Thanks !!

This is with regard to normal threads and not worker threads taken from the threadpool.

Update- I added a thread sleep to main thread and then added a breakpoint after that to find that the threads had been destroyed now.... I want to know how this is working.

Community
  • 1
  • 1
Kaustubh
  • 39
  • 7
  • 1
    If you want to see what the thread is doing then you have to enable unmanaged debugging. Project > Properties > Debug tab. Be sure to have the symbol server enabled, Tools > Options > Debugging > Symbols. – Hans Passant Dec 25 '15 at 11:05
  • I can debug a thread and see what it is doing, there is no issue with that. After the thread's call stack is empty (i.e I have gone through the thread completely), I can still see it in the list of managed threads with an empty call stack. _I wish to know how CLR threads are controlled and destroyed._ Obviously it was not garbage collection (CLR thread not thread object), but still I even tried GC.collect() just to verify.Thanks!! _Is there any way to call the thread garbage collector or whatever it is called, say like the garage collector for objects_ – Kaustubh Dec 25 '15 at 11:11
  • Jumping to conclusions can waste so much time. _apparently the garbage collector doesn't process CLR implemented managed threads_ is a case in point. – H H Dec 27 '15 at 08:45
  • A request to anybody giving a downvote... Please mention the reason for downvote so that I can avoid doing the same incorrect thing again ... – Kaustubh Jan 11 '16 at 15:43
  • All those threads that are called "Worker Thread" are all part of the [Thread Pool](https://msdn.microsoft.com/en-us/library/0ka9477y(v=vs.110).aspx), those have a very different behavior than "normal threads". You need to clarify are you just wanting to learn more about the thread pool or are you actually wanting to know how real threads are managed. – Scott Chamberlain Aug 01 '16 at 20:34

0 Answers0