尝试与tcpclient.connected一起使用的ConnectAsync

时间:2016-08-04 06:56:24

标签: vb.net networking tcp timeout

我正在使用以下代码尝试连接到系统,但处理超时。当没有连接时,tcpClient.Connected会在一段时间后给出NullReferenceException

    If tcpClient.ConnectAsync(IP, Port).Wait(1000) = False Then
        'Messagebox error
    End If
    If tcpClient.Connected Then
    .....
    End if

堆栈跟踪

bij System.Net.Sockets.TcpClient.get_Connected()
bij directory\System.vb:regel 47
bij System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bij System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

0 个答案:

没有答案