Neven Draskovic

Neven Draskovic

  • NA
  • 117
  • 139.9k

Using worker thread to read from serial port

Dec 14 2011 5:05 AM
Hello

First of all I have to say that I never worked with threads, this will be my first multi-thread application. This is my problem:
I have a card reader connected to a serial port, and I made an application that reads the cards serial number and with some other informations stores it into a database. However I have to use MessageBox to ask if user wants to read from a new card - this is extremely unpractical when working with a large number of cards. I tired to put the reading part into a loop, but that lock's all other controls, and I can't stop it once I'm done. I asked around a bit and everybody told me that threads are the right way to solve this problem. I did some reading and if I got it correct it should be possible to make 2 threads - one worker thread to read from the serial port and store the data, and the main (basic thread) one to stop the worker thread when I want to. This is my idea:
- User clicks a button that starts the worker.
- Worker reads from the serial port reader, and stores the data (like I said I actually have this part solved, I just need to make it more practical)
- All of the data that is read is automatically displayed in a DataGridView control (this part is also solved)
- User can stop the worker by clicking on another button.
Can you give me a link to some tutorial that could help me solve this problem, or if you can help me in any other way, I would be most thankful.

Again I am a complete beginner to multi-threading, so please bare that in mind when answering.
Thanks


Answers (10)