In the .NET BCL, there is a CurrentThread and a ProcessThread object. What is the difference between these?
Thanks
It is a hangover from a SQL Server project when .NET 2.0 was being designed. They pressed the CLR team really hard to break the link between the .NET Thread class and an operating system thread. They had reason to at the time, SQL Server supports "light-weight" threads that are implemented as fibers. A fiber is the Windows implementation of a "co-routine", something that was popular about 15 years ago.
The project was a bust, they couldn't get it reliable enough. Sadly, we are stuck with no easy way to map a Thread to a ProcessThread. Quite a loss. Maybe somebody, some day, will take advantage of the uncoupling, I haven't seen it done yet.
The only possible mapping you've got available now is to P/Invoke GetCurrentThreadId() inside the thread itself. That returns a TID that you can match to a ProcessThread.Id.
The CurrentThread
static property on the System.Threading.Thread
class is the current CLR System.Threading.Thread
instance. The CLR Thread is an abstraction over the underlying win32 thread. The System.Diagnostics.ProcessThread
class gives one access to the win32 threads, largely for perfomance tracking.
A key distinction of CLR threads is that they are not fixed to win32 threads.