如何处理与死进程关联的套接字. [英] how to handle sockets associated with dead processes.
问题描述
Windows 10,Visual Studio 2015专业版.
Windows 10, Visual Studio 2015 Professional.
在Visual Studio 2015 Professional中使用c#开发了WinForm应用程序. 应用程序使用端口8888与自定义Windows服务进行通信.
Developed a WinForm application using c# in visual studio 2015 Professional. Application communicates with a custom windows service using port 8888.
我已确定的问题是在服务或应用程序被挂起/终止时发生的.尝试再次启动它们,并获得有关正在使用的套接字的Windows错误. 清除此问题的唯一方法是重新启动计算机.
The problem I've determined occurs when the service or application are hung/terminated. Try to start them again and get windows errors about the socket being in use. The only way to clear this is to reboot computer.
我正在使用:
TcpClient客户端=新的TcpClient(ip地址,端口).
TcpClient client = new TcpClient(ipaddress,port).
有没有办法在代码中处理这种情况,所以我不必重新启动计算机?
Is there a way to handle this situation in code so I don't have to reboot the computer ?
谢谢.
推荐答案
您是否检查了是否可以使用以下方法终止挂起的进程"taskkill"命令行实用程序,资源可用了吗?
然后,如果出现以下情况,您可以使用 Process.Kill 函数结束此类进程 TcpClient 给出了例外.
Then maybe you can end such processes using the Process.Kill function if TcpClient gives exception.
这篇关于如何处理与死进程关联的套接字.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!