CurrentThread/ProcessThread objects

前端 未结 2 1829
無奈伤痛
無奈伤痛 2021-01-16 03:01

In the .NET BCL, there is a CurrentThread and a ProcessThread object. What is the difference between these?

Thanks

相关标签:
2条回答
  • 2021-01-16 03:42

    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.

    0 讨论(0)
  • 2021-01-16 03:44

    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.

    0 讨论(0)
提交回复
热议问题