Click to See Complete Forum and Search --> : killing thread


Rayman2
February 10th, 2006, 10:38 AM
hi

i need to kill thread when a button is clicked does any one know how can i do this :( i didnt find anything useful on net :(

but that button is not in the same thread

MrViggy
February 10th, 2006, 10:43 AM
Without any code, or specific examples, you'll have to someone get notice to the thread to quit itself.

Check out the How to end a worker thread (http://www.codeguru.com/forum/showthread.php?t=312452) FAQ.

Viggy

Rayman2
February 10th, 2006, 10:49 AM
?? isnt there nothing how to kill one thread from another

ovidiucucu
February 10th, 2006, 10:51 AM
[ Redirected thread ]

You cannot kill but teminate (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/terminatethread.asp) it. ;)

Note: read carefully the contents of page with that link.

Rayman2
February 10th, 2006, 10:55 AM
tnx

MrViggy
February 10th, 2006, 10:58 AM
Terminate thread is a dangerous call. It kills your thread immediately, no clean up, no graceful exit. You're better off using one of the methods in the FAQ.

Ahh, my bad. I clicked on the wrong LINK! Try this FAQ:

http://www.codeguru.com/forum/showthread.php?t=305166

Viggy

ovidiucucu
February 10th, 2006, 11:17 AM
Terminate thread is a dangerous call. It kills your thread immediately, no clean up, no graceful exit.
Correct. For that reason I said "read carefully...".
And what's quoted below, is from there ;)
MSDN
TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:

If the target thread owns a critical section, the critical section will not be released.
If the target thread is allocating memory from the heap, the heap lock will not be released.
If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.