getting data through serial port

  • Thread starter Thread starter Padu
  • Start date Start date
P

Padu

Hi,

I know that the System.IO.Ports.Serial port event for receiving data
(DataReceived) happens on a secondary thread, and that if there will be any
interaction of that data with the UI, it should be done through invoke.

Right now my application receives serial data and a class hierarchy is
responsible for handling it.
If I run the application, everything seems to work fine, but if I put a
breakpoint on it and try to follow, the weirdest things happen. For example,
sometimes it gives error messages, sometimes the application just stops
(vanishes is the correct word) and some other times VS IDE halts and
completely goes away. That usually happens if I put the mouse over any
variable and try to inspect its value.

For me it smells like threading problems (and if it smell like a duck and
walk like a duck...).

What is the best practice on handling the received data once it arrives (and
triggers the event) on the serial port? Do I have to synchronize it with the
main app thread?

Cheers

Padu
 
If you have data that both are accessing yes you have to synchronize them.

Cheers,

Greg Young
 
"Greg Young"
If you have data that both are accessing yes you have to synchronize them.

Cheers,

Greg Young


The think is that right now, no, there's no thread concurrency. The problem
only happens in the debugger, and it happens very uglyly. So I was wondering
if I'm doing things the correct way.

Cheers

Padu
 

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

Back
Top