Com port and priorities

  • Thread starter Thread starter Gianmaria
  • Start date Start date
G

Gianmaria

Hi,
i'm workin to a project where i use a serial port to send and receive data.
My objects send messages to the port by some methods.. no problem till now.
I receive and send data. The problem is that i have to send a string signal
every 25 seconds to tell the remote device i'm still connected.. now the
problem is that i cant control if that signal is sent while my users are
sending some other signals using objects methods. How can i stop all others
to send when my object is sending the keep alive signal?



regards
Gianmaria
 
Hi Gianmaria,

Take a look at using the System.Threading.Monitor class to gain
exclusive access to the serial port.

If the timing of your 25s control signal is extremely sensitive you'll
need to write the other object methods carefully. You need to prevent
another thread from grabbing the Monitor for long periods of time when
it sends user data.

See Jon's document for a good introduction to Monitor:
http://www.yoda.arachsys.com/csharp/multithreading.html
 
Back
Top