如何得到当前在VC中Debug的程序中的所有线程.

rain_Anda 2003-03-07 09:49:16

如题, 我知道spy可以,不过我看的不太明白,它好象给出了所有这个当前电脑中的进程和线程.

请高手指教!
...全文
75 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
masterz 2003-05-05
  • 打赏
  • 举报
回复
http://www.codeproject.com/threads/w32process.asp
masterz 2003-05-05
  • 打赏
  • 举报
回复
http://www.codeproject.com/threads/XTib.asp

you can get all threads of your application by code, I found this feature is useful, when some thread runs an infinite loop by mistake:)
BOOL CThreadList::Update(DWORD dwProcessID, BOOL bGetContext)
{
HANDLE hThreadSnap = NULL;
BOOL bRet = FALSE;
THREAD_INFORMATION_EX tie;
DWORD dwThisThread = ::GetCurrentThreadId(); // used for not killing ourself

// Take a snapshot of all threads currently in the system.

hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwProcessID);
if (hThreadSnap == INVALID_HANDLE_VALUE)
return FALSE;

// Fill in the size of the structure before using it.

tie.te32.dwSize = sizeof(THREADENTRY32);

// Walk the thread snapshot to find all threads of the process.
// If the thread belongs to the process, add its information
// to the display list.

if (Thread32First(hThreadSnap, &tie.te32))
{
do
{
//
// if the thread belongs to the given process...
//
if (tie.te32.th32OwnerProcessID == dwProcessID)
{
if(bGetContext && (dwThisThread != tie.te32.th32ThreadID))
{
//
// get some more information about this thread
//
HANDLE hThread = ::OpenThread(THREAD_GET_CONTEXT|THREAD_QUERY_INFORMATION, FALSE, tie.te32.th32ThreadID);
if(hThread != INVALID_HANDLE_VALUE)
{
::SuspendThread(hThread); // otherwise we dont get the context
{
tie.ctx.ContextFlags = CONTEXT_FULL;
::GetThreadContext(hThread, &tie.ctx);
}
::ResumeThread(hThread);
::CloseHandle(hThread);
}
}
#ifdef _VERBOSE_DEBUG
TRACE( "\nTID\t\t%d (@%i)\n", tie.te32.th32ThreadID, tie.te32.th32OwnerProcessID);
TRACE( "Base Priority\t%d\n", tie.te32.tpBasePri);
if(tie.ctx.ContextFlags)
{
TRACE("EIP\t\t0x%08x\n", tie.ctx.Eip);
TRACE("ESP\t\t0x%08x\n", tie.ctx.Esp);
}
#endif

#if defined(USE_STL)
push_back(tie);
#else
Add(tie);
#endif
ZeroMemory(&tie, sizeof(THREAD_INFORMATION_EX));
tie.te32.dwSize = sizeof(THREADENTRY32);
}
}
while (Thread32Next(hThreadSnap, &tie.te32));
bRet = TRUE;
}
else
bRet = FALSE; // could not walk the list of threads

// Do not forget to clean up the snapshot object.

CloseHandle (hThreadSnap);

return bRet;
}
In355Hz 2003-05-04
  • 打赏
  • 举报
回复
Debug 时选择菜单 Debug --> Threads 可以看到 Debug 进程的所有线程
realdreamer 2003-03-07
  • 打赏
  • 举报
回复
spy 有个进程列表. 在进程列表中找到你的进程, 展开, 就是你的线程列表.

winphoenix 2003-03-07
  • 打赏
  • 举报
回复
up

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧