在Delphi中是否有一个函数来获取当前执行的线程? [英] Is there a function in Delphi to get the current executing thread?
问题描述
我想要一个像GetCurrentThread这样的函数,它返回当前执行线程的TThread对象。我知道有一个Win32 API调用GetCurrentThread,但它返回线程Id。如果有可能从该ID获取TThread对象也很好。
I want a function like GetCurrentThread which returns a TThread object of the current executing thread. I know there is a Win32 API call GetCurrentThread, but it returns the thread Id. If there is a possibility to get TThread object from that ID that's also fine.
推荐答案
最新版本的Delphi,Delphi 2009,在TThread类上有一个CurrentThread类属性。
The latest version of Delp Delphi 2009, has a CurrentThread class property on the TThread class.
如果它是本机线程,这将返回正确的Delphi线程对象。如果线程是一个外星人线程,即使用某种其他机制创建或从第三方线程回调,那么它将在线程句柄周围创建一个包装线。
This will return the proper Delphi thread object if it's a native thread. If the thread is an "alien" thread, i.e. created using some other mechanism or on a callback from a third party thread, then it will create a wrapper thread around the thread handle.
这篇关于在Delphi中是否有一个函数来获取当前执行的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!