How to set the thread display name for the thread list debug window
2010-11-05 00:25 i2945 [permalink]
This little trick appears to work in the Delphi debugger also! Use this code to set the debug display name for the current thread:
interface
function IsDebuggerPresent: BOOL; stdcall;
implementation
uses Windows;
function IsDebuggerPresent; external 'kernel32.dll';
procedure SetThreadName(ThreadDisplayName:AnsiString);
var
ThreadInfo:record
dwType:LongWord;
szName:PAnsiChar;
dwThreadID:LongWord;
dwFlags:LongWord;
end;
begin
if IsDebuggerPresent then
begin
ThreadInfo.dwType:=$1000;
ThreadInfo.szName:=PAnsiChar(ThreadDisplayName);
ThreadInfo.dwThreadID:=LongWord(-1);//calling thread
ThreadInfo.dwFlags:=0;
try
RaiseException($406D1388,0,SizeOf(ThreadInfo) div SizeOf(LongWord),@ThreadInfo);
except
//
end;
end;
end;