Click here to Skip to main content
16,005,734 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Stopping a thread Pin
Vikash Dubey27-Sep-04 20:44
Vikash Dubey27-Sep-04 20:44 
GeneralRe: Stopping a thread Pin
Sujan Christo27-Sep-04 22:01
Sujan Christo27-Sep-04 22:01 
GeneralRe: Stopping a thread Pin
22491727-Sep-04 21:34
22491727-Sep-04 21:34 
GeneralRe: Stopping a thread Pin
Sujan Christo27-Sep-04 21:54
Sujan Christo27-Sep-04 21:54 
GeneralRe: Stopping a thread Pin
Andrzej Markowski27-Sep-04 22:49
Andrzej Markowski27-Sep-04 22:49 
GeneralRe: Stopping a thread Pin
Sujan Christo28-Sep-04 1:40
Sujan Christo28-Sep-04 1:40 
GeneralRe: Stopping a thread Pin
Sujan Christo28-Sep-04 21:12
Sujan Christo28-Sep-04 21:12 
GeneralRe: Stopping a thread Pin
Andrzej Markowski28-Sep-04 22:24
Andrzej Markowski28-Sep-04 22:24 
Here's an example which manages with WAIT_OBJECT_1. The example demonstates how to print to the debug output every 1 s:
// In your thread class:
// Declare m_eventShutdown variable of the type CEvent.
// Add function CYourThreadClass::ShutdownThread { m_eventShutdown.SetEvent();}
// Declare m_eventPrintToDebug variable of the type CEvent.
// Add function CYourThreadClass::PrintToDebug { m_eventPrintToDebug.SetEvent();}
//
//In your thread function:
//
int CYourThreadClass::ThreadFunction()
{
while(1)
{
int nCounter = 0;
HANDLE h[2];
h[0] = m_eventShutdown.m_hObject;
h[1] = m_eventPrintToDebug.m_hObject;
DWORD dwRet = ::WaitForMultipleObjects(2,h,FALSE,INFINITE)
if(dwRet==WAIT_OBJECT_0) // exit thread
return 0; 
else if(dwRet==WAIT_OBJECT_1) // print to the debug output
TRACE("Counter = %d\n",n_Counter++); 
else if(dwRet==WAIT_TIMEOUT)
// never here if the time-out interval = INFINITE
else if(dwRet==WAIT_FAILED)
// handle error
}
}
//
//In your UI thread call SetTimer(1,1000,NULL) and in OnTimer call CYourThreadClass::PrintToDebug. 
//To terminate the worker thread call CYourThreadClass::ShutdownThread from your UI thread.

GeneralRe: Stopping a thread Pin
Sujan Christo28-Sep-04 22:57
Sujan Christo28-Sep-04 22:57 
GeneralRe: Stopping a thread Pin
Sujan Christo28-Sep-04 23:52
Sujan Christo28-Sep-04 23:52 
GeneralRe: Stopping a thread Pin
David Crow28-Sep-04 4:35
David Crow28-Sep-04 4:35 
GeneralRe: Stopping a thread Pin
Sujan Christo28-Sep-04 19:48
Sujan Christo28-Sep-04 19:48 
GeneralCStatic with bitmap Pin
GDavy27-Sep-04 20:20
GDavy27-Sep-04 20:20 
GeneralRe: CStatic with bitmap Pin
Sujan Christo27-Sep-04 21:35
Sujan Christo27-Sep-04 21:35 
GeneralRe: CStatic with bitmap Pin
Andrzej Markowski27-Sep-04 21:59
Andrzej Markowski27-Sep-04 21:59 
GeneralThanks for solution+ memory problem? Pin
GDavy27-Sep-04 22:16
GDavy27-Sep-04 22:16 
GeneralRe: Thanks for solution+ memory problem? Pin
Andrzej Markowski27-Sep-04 23:54
Andrzej Markowski27-Sep-04 23:54 
GeneralDirectShow Pin
dudic27-Sep-04 18:32
dudic27-Sep-04 18:32 
GeneralMointor File activity Pin
Anonymous27-Sep-04 18:26
Anonymous27-Sep-04 18:26 
GeneralRe: Mointor File activity Pin
Vikash Dubey27-Sep-04 20:54
Vikash Dubey27-Sep-04 20:54 
GeneralDifferences between semaphores,critical section and mutexes Pin
Raghunandan S27-Sep-04 17:57
Raghunandan S27-Sep-04 17:57 
GeneralRe: Differences between semaphores,critical section and mutexes Pin
22491727-Sep-04 18:00
22491727-Sep-04 18:00 
GeneralProblem with CEdit box Pin
Neelesh K J Jain27-Sep-04 17:48
Neelesh K J Jain27-Sep-04 17:48 
GeneralRe: Problem with CEdit box Pin
Sujan Christo27-Sep-04 18:15
Sujan Christo27-Sep-04 18:15 
GeneralRe: Problem with CEdit box Pin
Neelesh K J Jain27-Sep-04 19:11
Neelesh K J Jain27-Sep-04 19:11 

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.