| | |
thread abort
![]() |
•
•
Join Date: Feb 2008
Posts: 98
Reputation:
Solved Threads: 2
I am running a thread that does something, then sleeps for a while. If the program closes it continues to sleep to completion. How do I get it to abort immediatly, even if in the middle of sleeping?
and in my mainform destructor which controls the thread:
Thanks.
C++ Syntax (Toggle Plain Text)
void commThread::ThreadEntryPoint1() { while(1) { //do work Sleep(15000); //15 second sleep } }
and in my mainform destructor which controls the thread:
C++ Syntax (Toggle Plain Text)
~Form1() { if (components) { delete components; } if(Thread1->IsAlive) { //Thread1->Interrupt(); Thread1->Abort(); } }
Thanks.
Instead of Sleep() you can use WaitForSingleObjectEx(), which lets you abort the sleep early.
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
You may use TerminateThread function, it will terminate your thread immediatly, but it is bad practice. Right decision is to follow Ancient Dragon's recomendation and use some of synchronization objects instead -- for example event. Thread may sleep, waiting some event to be signaled, then awake and abort himself with proper resource cleanup, etc...
![]() |
Similar Threads
- Send data on a serial port (C++)
- Thread's colliding? (C#)
- Timer, tickcount, ticks? (C#)
- how to kill a thread in python? (Python)
- Exception error (HTML and CSS)
- IE Browser shutting down and shows error on desktop (Java)
- Error Message in the VM (Windows NT / 2000 / XP)
- How to exit without exit? (C++)
Other Threads in the C++ Forum
- Previous Thread: Problem when using a template classes to store user-defined types
- Next Thread: How to show size of a variable
Views: 1212 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment beginner binary browser c++ c/c++ calculator char class classes code compile compiler constructor conversion convert count delete dll dynamic encryption error file files filestream fstream function functions game givemetehcodez graph graphics gui homework iamthwee input int lazy linker list loop loops map math matrix member memory newbie number object objects opengl output parameter path pointer pointers problem program programming project python random read reading recursion recursive reference server sockets sort sorting spoonfeeding string strings struct student studio template templates text time tree undefined url variable vc++ vector video visual visualstudio win32 window windows winsock wordfrequency






