Andy

Andy

  • NA
  • 1
  • 0

Handling events generated in a thread

Jun 18 2009 1:03 PM

Hi all
I monitor the serial port within a worker thread. As data arrives I buffer it. When the data is complete I copy it in to variable shared with the container class. I generate an event within the worker thread to let the outside world know there is new data.
When the event is detected in the main thread I read a copy of the exposed data from the containing class. I then do things with the data. e.g. write it to a database etc..
When the  the device I'm monitoring tells me it has no more data, and I go off and do other things, one action I do is to thread.join the worker thread i.e. I don't need it any more.
The problem is that because the event to finish is generated within the worker thread, all the code called by the worker event seems to be handled within the worker thread, so in effect it cuts its own throat and crashes.
Does anyone know how to set an event in a thread. Pick it up in the main thread and then any further actions transferred over to the main thread?
 
thanks in advance