tags:

views:

26

answers:

2

Hi guys,

I have a small application to open the door using a relay controller. I have to open and close the COM port all time if someone comes in. In the morning, when lots of people come together controller responds very slow and i need to solve this problem fast.

My question is, will i run in to memory issues if i keep it open all time time? will open port recycle if application crashes and restart ?

+2  A: 

I don't think you'll run into memory problems. I wrote a program that uses a bar code scanner that uses a COM port to listen to events from the scanner. I open it when the program launches and keep it open until the program closes with no issues at all.

The only thing to worry about is that the COM port can only be used by one object at a time, so if your program already has it open and tries to open it again, that's a problem.

The program may leave the COM port open, so you're best off to try opening it, and if that fails, try closing it (two separate try...catch blocks) and then try opening it again. It's a hassle, but in my app it turned out to reduce the number of errors I had to troubleshoot. I just open/close/open every time the program loads to be safe.

David Stratton
+1  A: 
  • no issue with keeping it open
  • it will close the com port if the app dies

only thing is, sometimes if you don't shut down the com port properly it can keep your app alive as a process in a lingering non dying state which keeps the com port.

Keith Nicholas