Un-threading my Threads!

P

Paul Cheetham

Hi,

I have a thread in my application that is listening to the Serial port
using GetCommEvents.
When something is received, it generates an event, and then goes back to
waiting for more data. - I am using this for a swipe card reader.

When a card is swiped, an event is generated, and I log the user into my
application. The card reader is no longer required at this point so I
disable it, which kills off the thread.
Now - because the card reader thread generated the event, my entire
application seems to be using that thread, and so as soon as the thread
gets killed, all my windows disappear, and the main thread is left
running in the background with nothing to do.

I have tried creating a new thread in the event handler, so that when
the first thread is stopped it would then keep running on the new one -
but that one seems to get stopped as well with the same results, even
though it is declared globally etc.

Can anybody tell me what I need to do to get around this problem, as I'm
sure it's a fairly common problem, but I'm pretty new to multi-threading
and it's giving me a headache!


Thankyou in advance.

Paul Cheetham
 
S

Slow Learner

Rather than raising an event, you can do something similar and execute a
delegate on the main form from your thread. The execution will occur on the
main process thread, not your worker thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top