hello at all professional thread-user!
i've implemented a single thread in my appl to grab some data from a sensor. in the thread i call a simple visualisation for each of the data packages.
for creating the thread i use the common way of doing like descriped in visual c++ in 21 days or similar easy books.
for better discussion i just paste in the main lines:
// (A) Worker-Thread starten und Zeiger auf struct GThreadData übergeben
_thread = AfxBeginThread(GrabberThread, (LPVOID) _threadData, liPriority);
// (B) Handle für Thread holen
HANDLE hThread = _thread->m_hThread;
// auf Absterben des Threads warten
::WaitForSingleObject(hThread, INFINITE);
now to my problem. both - starting and stopping - i've implemented in a function called SuspendSensor and use a simple BOOL to start and to stop. (A) seems to be ok, cause the appl does what it should do. (B) doesn't work at all. (B) i've also implemented in the OnExit funktion, but i think it will be overwrited by some other mechanisms from MFC while stopping the whole appl. if i call the SuspendSensor funtion with FALSE in the argument (that means stop the thread) during the running appl my appl crashs.
what is wrong? are there other ways to force the program to stop a thread such as i have created?
your greenhorn in programming with threads
hilmar
i've implemented a single thread in my appl to grab some data from a sensor. in the thread i call a simple visualisation for each of the data packages.
for creating the thread i use the common way of doing like descriped in visual c++ in 21 days or similar easy books.
for better discussion i just paste in the main lines:
// (A) Worker-Thread starten und Zeiger auf struct GThreadData übergeben
_thread = AfxBeginThread(GrabberThread, (LPVOID) _threadData, liPriority);
// (B) Handle für Thread holen
HANDLE hThread = _thread->m_hThread;
// auf Absterben des Threads warten
::WaitForSingleObject(hThread, INFINITE);
now to my problem. both - starting and stopping - i've implemented in a function called SuspendSensor and use a simple BOOL to start and to stop. (A) seems to be ok, cause the appl does what it should do. (B) doesn't work at all. (B) i've also implemented in the OnExit funktion, but i think it will be overwrited by some other mechanisms from MFC while stopping the whole appl. if i call the SuspendSensor funtion with FALSE in the argument (that means stop the thread) during the running appl my appl crashs.
what is wrong? are there other ways to force the program to stop a thread such as i have created?
your greenhorn in programming with threads
hilmar