如何获取Win32线程的名称? [英] How to get the name of a Win32 Thread?

查看:395
本文介绍了如何获取Win32线程的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在Windows下设置线程名称的非直观过程(请参阅如何设置名称为Win32 Thread?)。有没有办法得到线程的名称?我没有看到任何Windows API让我这样做( http://msdn.microsoft.com/en-us/library/windows/desktop/ms684847(v = vs.85).aspx )。



如果你设置了一个线程名称那么IDE的调试器将为您存储它,这使它更容易调试。
然而,该名称从未真正附加到线程的Windows API调用。



如果你运行你的应用程序没有调试器,那么设置线程名称没有效果,因此您无法检索该名称。



即使可以访问 - 我不会编写只与调试器连接的代码。更好地存储自己的名称和句柄。


I know of the non-intuitive process to set the name of a thread under Windows (see "How to set name to a Win32 Thread?"). Is there a way to get the name of the thread? I don't see any Windows API that lets me do this (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684847(v=vs.85).aspx).

解决方案

There is no such WinAPI call since there exists no such thing as thread names.

If you set a thread name then the debugger of your IDE will store it for you, which makes it easier to debug. However the name is never really attached to the thread by a windows API call.

If you run your application without a debugger then setting a thread name has no effect, therefore you can't retrieve the name.

Even if it would be accessible - I wouldn't write code that works only with a debugger attached. Better store the name for yourself together with the handle.

这篇关于如何获取Win32线程的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆