My C# .net application currently does the following (among other things):
- Creates a thread which opens a socket on a specific port and waits for an instruction.
- Message comes in, socket thread reads the message and raises an event.
- An event handler calls the necessary functions to parse the message and performs the necessary action, for instance, launching an application.
- The specified external "application" launches, asynchronously.
When my application restarts, but the external application does not close, the socket doesn't seem to ever close. Then when I try to start up communication on that port again I get an error. However, as soon as I close the external application I am able to open a socket on that port.
It seems like my program is not closing down properly. It should be killing the socket when it exits, however when the external process is running that socket never closes.
Any ideas?