如何从Visual Studio中手动终止特定的(运行中的)线程 [英] How to manually kill a specific (running) thread from Visual Studio

查看:394
本文介绍了如何从Visual Studio中手动终止特定的(运行中的)线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于测试目的,我需要手动从Visual Studio(或其他允许我执行此操作的工具)中杀死一个命名线程(在调试会话中)?

For the purpose of testing, I need to manually kill a named thread (in a debugging session) from Visual Studio - or any other tool that allows me to do that?

但是,Visual Studio 2010中的Threads调试窗口在线程的上下文菜单中仅具有Freeze选项,而Sysinternal的 ProcessExplorer 仅列出进程,而不列出线程.

But the Threads Debug Window in Visual Studio 2010 only has a Freeze option in the thread's context menu, and Sysinternal's ProcessExplorer only lists processes, not threads.

有没有办法手动杀死特定的(正在运行的)线程?

Is there a way to manually kill a specific (running) thread?

推荐答案

仅仅杀死一个线程并不容易,因为该语言的设计人员希望避免以下问题:您的线程需要一个锁,然后才将其杀死它可以释放它...现在,任何需要该锁的人都会被卡住.

It's not easy to just kill a thread because the designers of the language want to avoid the following problem: your thread takes a lock, and then you kill it before it can release it... now anyone who needs that lock will get stuck.

您要做的是使用一些全局变量告诉线程停止.您必须手动在线程代码中检查该全局变量,如果看到它表明您应该停止,则返回该变量.

What you have to do is use some global variable to tell the thread to stop. You have to manually, in your thread code, check that global variable and return if you see it indicates you should stop.

这篇关于如何从Visual Studio中手动终止特定的(运行中的)线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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