I am developing a .Net profiler.. I use ILRewriting for this..
I need to trace the managed thread creations and destroys.
Need to know the threading related function that will be called at the beginning of the thread and during the end of the thread , i can inject my code to it and record whenever the event happens.
Any ideas about the default function that will be called at the time of thread creation and ends..??
OR else is there any other way to capture the managed thread creation and destroying events??
I know that we can trace by setting the threading event mask.. but i need to capture particular managed threads not all the threads..
As Hans pointed out, the CLR notifies the profiler of thread creation/destruction using ThreadCreated and ThreadDestroyed callbacks. Note: If the runtime shuts down before the thread terminates, then you won't get the ThreadDestroyed callback ... but I think the more likely reason you don't get the ThreadDestroyed callback is that IIS (I assume by 'page load' you are referring to asp .NET pages) decided to keep the thread around for future requests as an optimization, it may decide to terminate it later if it thinks it has enough other threads.
Also, regarding your second comment on the question, there is no relation between ThreadID and ManagedThreadID. I believe the ThreadID is a reference to an internal data structure (treat it as an opaque value, don't try to interpret it) and the ManagedThreadID appears to be a simple number sequentially allocated as threads first enter managed code. If you want identify which ThreadID corresponds with which managed thread, I can think of 3 options: