Visual Studio 2019 c#.
I created a custom service. It listens to a specific port to communicate with another piece of software on the computer using the TcpListener.
tcpListener serverSocket = new TcpListener(localAddr, port)
try {
serverSocket.Start();
//process stuff in here
}
If the service hangs and has to be force restarted or crashes, the socket does not get "released" and when the service tries to start again, I get an error that the socket in already in use.
Is there anyway to handle this situation ? The only way I have found to "clear" it is to reboot the computer.
Any ideas greatly appreciated.