【发布时间】:2021-08-24 06:38:07
【问题描述】:
我有 .net 应用程序,它在登录后 ping 特定端口。我已经包围了 try catch 中的逻辑,并在我的日志中捕获了 System.net.webException。但在某些 Windows 机器中,这会导致应用随机崩溃。
Error Message: WebException
Exception Type: System.Net.WebException
Error Location : Unable to connect to the remote server
InnerException: System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 127.0.0.1:9000
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
StackTrace: at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at tpsyncagent.MainWindow.<ConnectToTally>d__36.MoveNext() in C:\code\tpdesktopsyncagent\MainWindow.xaml.cs:line 247
这是代码片段
try
{
Stream dataStream = TallyRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
}
catch(Exception e)
{
//logging code
}
【问题讨论】:
-
你可以检查windows事件查看器是否有异常
标签: c# .net wpf exception crash