I am working on vb.net dll, for reading values from a bar code scanner, connected via serial comm port. If the app closes irregularly (i.e.: killed by task manager), the ports stay bound to the app, and i have to restart the whole program. I would like to know if there is a way to somehow release those ports, so i can only restart the crashed app?
Port is initialized:
Public Sub Init(pPort As String)
port = New SerialPort(pPort, 9600, Parity.None, 8, StopBits.One)
port.Handshake = Handshake.None
port.ReadTimeout = 1000
port.WriteTimeout = 1000
port.RtsEnable = True
port.DtrEnable = True
port.Open()
End Sub
Port is closed after use:
Public Sub Close()
port.Close()
port = Nothing
End Sub
As said before, if the app closes irregularly, it does not close the port. If I try to initialize again i get the error port denied. What can I do in this case?