Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to change day with button click. Pin
Ashish Chauhan11-Mar-08 23:33
Ashish Chauhan11-Mar-08 23:33 
GeneralRe: How to change day with button click. Pin
Rajesh R Subramanian11-Mar-08 23:41
professionalRajesh R Subramanian11-Mar-08 23:41 
AnswerRe: How to change day with button click. Pin
Rajesh R Subramanian12-Mar-08 0:05
professionalRajesh R Subramanian12-Mar-08 0:05 
GeneralRe: How to change day with button click. Pin
Ashish Chauhan12-Mar-08 0:58
Ashish Chauhan12-Mar-08 0:58 
GeneralRe: How to change day with button click. Pin
Rajesh R Subramanian11-Mar-08 4:31
professionalRajesh R Subramanian11-Mar-08 4:31 
QuestionQuestion about how to kill thread that i create with _beginthreadex ? Pin
Yanshof10-Mar-08 20:35
Yanshof10-Mar-08 20:35 
AnswerRe: Question about how to kill thread that i create with _beginthreadex ? Pin
Maxwell Chen10-Mar-08 20:40
Maxwell Chen10-Mar-08 20:40 
AnswerRe: Question about how to kill thread that i create with _beginthreadex ? Pin
Peter Weyzen10-Mar-08 20:41
Peter Weyzen10-Mar-08 20:41 
There's a few ways to do it.

The nice way:

Before starting the thread, create an event object (CreateEvent). Share this event handle with your thread, check it periodically -- and when it becomes signalled, have the thread exit itself. It's always best for the thread to exit gracefully.

HANDLE hEvent = CreateEvent();
_beginThreadEx( NULL, 0, YourThreadFunc, hEvent, 0, &ThreadID );


unsigned int __stdcall YourThreadFunc( LPVOID pData )
{
   HANDLE hEvent = (HANDLE)pData;
   while ( WaitForSingleObject(hEvent,0) != WAIT_OBJECT_0 )
   { 
       DoSomething();
   }
   return 0;
}


SetEvent(hEvent);


The nasty way:
TerminateThread( threadHandle );

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>

GeneralRe: Question about how to kill thread that i create with _beginthreadex ? [modified] Pin
Yanshof10-Mar-08 21:15
Yanshof10-Mar-08 21:15 
GeneralRe: Question about how to kill thread that i create with _beginthreadex ? Pin
Cedric Moonen10-Mar-08 21:33
Cedric Moonen10-Mar-08 21:33 
GeneralRe: Question about how to kill thread that i create with _beginthreadex ? Pin
Yanshof10-Mar-08 21:39
Yanshof10-Mar-08 21:39 
GeneralRe: Question about how to kill thread that i create with _beginthreadex ? Pin
Peter Weyzen10-Mar-08 21:54
Peter Weyzen10-Mar-08 21:54 
QuestionHow virtual destructor works under the hood? Pin
abhijitr10-Mar-08 19:41
abhijitr10-Mar-08 19:41 
AnswerRe: How virtual destructor works under the hood? Pin
Peter Weyzen10-Mar-08 19:47
Peter Weyzen10-Mar-08 19:47 
GeneralRe: How virtual destructor works under the hood? Pin
Rajkumar R10-Mar-08 23:53
Rajkumar R10-Mar-08 23:53 
GeneralRe: How virtual destructor works under the hood? Pin
Peter Weyzen11-Mar-08 7:46
Peter Weyzen11-Mar-08 7:46 
GeneralRe: How virtual destructor works under the hood? Pin
Rajkumar R11-Mar-08 8:27
Rajkumar R11-Mar-08 8:27 
GeneralRe: How virtual destructor works under the hood? Pin
Peter Weyzen11-Mar-08 8:49
Peter Weyzen11-Mar-08 8:49 
AnswerRe: How virtual destructor works under the hood? Pin
Maxwell Chen10-Mar-08 20:36
Maxwell Chen10-Mar-08 20:36 
GeneralMissing Start Point Pin
Member 461894910-Mar-08 18:29
Member 461894910-Mar-08 18:29 
QuestionRe: Missing Start Point Pin
Maxwell Chen10-Mar-08 19:08
Maxwell Chen10-Mar-08 19:08 
GeneralRe: Missing Start Point Pin
Sameerkumar Namdeo10-Mar-08 22:27
Sameerkumar Namdeo10-Mar-08 22:27 
GeneralWorker thread-&gt;crash Pin
lavate malllik10-Mar-08 17:39
lavate malllik10-Mar-08 17:39 
GeneralRe: Worker thread-&gt;crash Pin
Stephen Hewitt10-Mar-08 18:00
Stephen Hewitt10-Mar-08 18:00 
GeneralRe: Worker thread-&gt;crash Pin
Peter Weyzen10-Mar-08 19:49
Peter Weyzen10-Mar-08 19:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.