terminate thread
-
hi, what method do you use to terminate a thread? i am in a situation that after few thousands of restart a thread? it failed for me to create thread for me with AfxBeginThread(). i used TerminateThread() to terminate thread from the main program, in msdn, it is not a good method to terminate a thread. i guess it leads to the problem that i can't create thread when restart. do you have any good method to terminate thread? thanks, jim
-
hi, what method do you use to terminate a thread? i am in a situation that after few thousands of restart a thread? it failed for me to create thread for me with AfxBeginThread(). i used TerminateThread() to terminate thread from the main program, in msdn, it is not a good method to terminate a thread. i guess it leads to the problem that i can't create thread when restart. do you have any good method to terminate thread? thanks, jim
-
hi, what method do you use to terminate a thread? i am in a situation that after few thousands of restart a thread? it failed for me to create thread for me with AfxBeginThread(). i used TerminateThread() to terminate thread from the main program, in msdn, it is not a good method to terminate a thread. i guess it leads to the problem that i can't create thread when restart. do you have any good method to terminate thread? thanks, jim
Just
return
from the threadproc and your thread is terminated. It's not even required that you callAfxEndThread
Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win]
-
You can usually end your thread from within the thread with Afxenthread(); If you want to do that remotedely from outside the thread, just use an event to tell your thread to end. ~RaGE();
-
hi, what method do you use to terminate a thread? i am in a situation that after few thousands of restart a thread? it failed for me to create thread for me with AfxBeginThread(). i used TerminateThread() to terminate thread from the main program, in msdn, it is not a good method to terminate a thread. i guess it leads to the problem that i can't create thread when restart. do you have any good method to terminate thread? thanks, jim
There are couple of ways to terminate thread safely based on the problem here is the event approach, - CreateEvent() (named event to use across process'es) - CreateThread (or AfxBEginThread) and pass event as Thread Param - Keep listening to Event Signaling at application atomic times (WaitForSingleObject). - when Event is signaled or job is done, just return (use AfxEndThread() with AfxBeginThread() - MFC way) From main/any thread signal the event, when u want to stop the thread safely. To brutally kill the thread use: TerminateThread() Refer to samples in codeproject.com OR codeguru.com. Hth, Ramu
-
There are couple of ways to terminate thread safely based on the problem here is the event approach, - CreateEvent() (named event to use across process'es) - CreateThread (or AfxBEginThread) and pass event as Thread Param - Keep listening to Event Signaling at application atomic times (WaitForSingleObject). - when Event is signaled or job is done, just return (use AfxEndThread() with AfxBeginThread() - MFC way) From main/any thread signal the event, when u want to stop the thread safely. To brutally kill the thread use: TerminateThread() Refer to samples in codeproject.com OR codeguru.com. Hth, Ramu
Ramu, thank you! your information is so useful. currently, i am using a TerminateThread() to kill a thread. due to some reasons, i need to restart the threads few mins once. after few days running, it failed to to create thread with AfxBeginThread(). i doubted that related to using TerminateThread() to kill a thread. so, i am trying other methods. anyway, your information is useful and let me check with it! thanks, jim