问题
I'm using the TcpClient and TcpListener classes to establish a connection between two computers. I've read documentation and questions online, but can't seem to find the answer to this question:
Is it necessary to call Sockets.Close() before the program ends, or will VB close all sockets which were opened by the program for me before it ends? In addition, what if the program crashes?
From what I've seen, the suggested implementation of the TcpClient and TcpListener classes suggest closing the sockets in the Finally block so that they are closed even if any exceptions occur.
However, this finally block is not necessarily called if I just simply close the program by calling End, and I'm not entirely sure if it is called if a crash outside of the try block or on another thread occurs.
来源:https://stackoverflow.com/questions/38946641/tcpclient-listener-do-i-have-to-call-sockets-close-when-my-program-ends