嗨,我有一段代码使用套接字连接到服务器
Try
'Connect To The Server
Dim socketclient As New TcpClient
Dim success
Dim result
result = socketclient.BeginConnect(ip, port, socket.EndConnect, socketclient)
success = result.AsyncWaitHandle.WaitOne(5000, True)
If socketclient.Connected = False Then
Throw New Exception("Server is offline")
End If
catch ex as exception
End Try
如你看到的。如果服务器离线,我的 try-catch 设置不会捕获错误“主机未知”我相信这是因为错误发生在异步调用期间。如果这是真的,如何在异步调用中捕获错误?