Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manually kill a specific (running) thread from 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?

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?

like image 253
ateiob Avatar asked Nov 04 '22 12:11

ateiob


1 Answers

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.

like image 85
dsgriffin Avatar answered Nov 12 '22 14:11

dsgriffin