CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  进程/线程/DLL

VC中如何察看当前运行的所有线程,并切换到该线称??

楼主lwglucky(才鸟)2006-07-03 11:46:22 在 VC/MFC / 进程/线程/DLL 提问

我一个程序的某个线程不停的创建、退出。(在vc的output窗口不停的显示)。。。程序比较大,也不是我写的。。但是这个线程创建、退出似乎造成了一些问题。  
  我不知道如何在vc下察看当前进程的所有线程,并切换过去。  
  我在网上一篇文章看到如下:  
    “我们可以用Visual   Studio调试器附上这个应用程序,切换到这个线程下“     -----   请问具体该如何做??? 问题点数:100、回复次数:11Top

1 楼DentistryDoctor(不在无聊中无奈,就在沉默中变态)回复于 2006-07-03 11:58:50 得分 0

查看有哪些线程还好办,要切换过去比较难办。因为线程的调度是由操作系统控制的。Top

2 楼lxpws(你被耍了)回复于 2006-07-03 12:00:09 得分 0

vs2003:调试-》窗口-》线程,然后双击显示线程的条目即可切换。要处于调试状态才能找到。Top

3 楼lxpws(你被耍了)回复于 2006-07-03 12:02:49 得分 0

DentistryDoctor说得对,切换的话也只能是切换到此线程当前执行到的源代码,并不是执行流程的切换。Top

4 楼pomelowu(羽战士)回复于 2006-07-03 12:11:44 得分 0

1、Thread   Walking   (From   MSDN,参考http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/tool_help_library.asp)  
   
  A   snapshot   that   includes   the   thread   list   contains   information   about   each   thread   of   each   currently   executing   process.   You   can   retrieve   information   for   the   first   thread   in   the   list   by   using   the   Thread32First   function.   After   retrieving   the   first   thread   in   the   list,   you   can   retrieve   information   for   subsequent   threads   by   using   the   Thread32Next   function.   Thread32First   and   Thread32Next   fill   a   THREADENTRY32   structure   with   information   about   individual   threads   in   the   snapshot.    
   
   
  You   can   enumerate   the   threads   of   a   specific   process   by   taking   a   snapshot   that   includes   the   threads   and   then   by   traversing   the   thread   list,   keeping   information   about   the   threads   that   have   the   same   process   identifier   as   the   specified   process.  
   
  You   can   retrieve   an   extended   error   status   code   for   Thread32First   and   Thread32Next   by   using   the   GetLastError   function.  
   
  Note     The   contents   of   the   th32ThreadID   member   of   THREADENTRY32   is   a   thread   identifier   and   can   be   used   by   any   functions   that   require   a   thread   identifier.  
   
   
  2、SwitchToThread   APITop

5 楼goodboyws(深夜不眠者(VCMVP))回复于 2006-07-03 12:53:32 得分 0

1.toolhelp32   枚举特定进程的所有线程列表    
  #include   <windows.h>  
  #include   <tlhelp32.h>  
  #include   <stdio.h>  
   
  BOOL   RefreshThreadList   (DWORD   dwOwnerPID)    
  {    
          HANDLE                 hThreadSnap   =   NULL;    
          BOOL                     bRet                 =   FALSE;    
          THREADENTRY32   te32                 =   {0};    
     
          //   Take   a   snapshot   of   all   threads   currently   in   the   system.    
   
          hThreadSnap   =   CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,   0);    
          if   (hThreadSnap   ==   INVALID_HANDLE_VALUE)    
                  return   (FALSE);    
     
          //   Fill   in   the   size   of   the   structure   before   using   it.    
   
          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,   &te32))    
          {    
                  do    
                  {    
                          if   (te32.th32OwnerProcessID   ==   dwOwnerPID)    
                          {    
                                  printf(   "\nTID\t\t%d\n",   te32.th32ThreadID);    
                                  printf(   "Owner   PID\t%d\n",   te32.th32OwnerProcessID);    
                                  printf(   "Delta   Priority\t%d\n",   te32.tpDeltaPri);    
                                  printf(   "Base   Priority\t%d\n",   te32.tpBasePri);    
                          }    
                  }    
                  while   (Thread32Next(hThreadSnap,   &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);    
  }Top

6 楼lwglucky(才鸟)回复于 2006-08-11 01:02:51 得分 0

都没有说到电子上Top

7 楼cenchure(达到)回复于 2006-08-11 08:25:34 得分 0

threadproc   中   启动   一个事件通知,   在主线成   中   waitmultiobject     ,SwitchToThread     可以让   system   切换到   下一个   thread   ,      
  case   THREAD1   :  
        //if   not     you   need   ,switch   to     next   thread  
                    SwitchToThread();  
  break;  
  case   THREAD2:  
        ..............................................Top

8 楼yzcurry(什么都不会)回复于 2006-08-11 14:41:58 得分 0

很难的吧??我没想过,要到进程里再看线程,大哥你没事情做了吧???真是蚂蚁体内找五脏啊Top

9 楼eparg()回复于 2006-08-12 09:50:54 得分 50

人家是问调试器怎么来选择不同的目标thread来调试,不是程序里面切换thread  
   
  真是服了楼上几位兄弟  
   
  如果要作多县城调试,vs   ide不是一个很好的工具。用windbg吧。切换thread用简单的  
   
  ~thread   number  
   
  就可以了  
   
   
  详细的可以参考:  
  http://blogs.msdn.com/lixiong/attachment/687357.ashx  
  Top

10 楼superarhow(苏泊尔耗)回复于 2006-08-12 14:21:57 得分 50

先break下来,然后点  
  菜单:调试->窗口->线程  
  会看到所有线程列表,在线程上点右键,有个“切换到”菜单。  
  vs2003和2000都有。Top

11 楼jyl168(jiangyouliang)回复于 2007-03-07 17:56:45 得分 0

markTop

相关问题

关键词

得分解答快速导航

  • 帖主:lwglucky
  • eparg
  • superarhow

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo