您将需要使用async
BeginConnect方法
TcpClient而不是尝试同步连接,这是构造函数所做的。像这样:
var client = new TcpClient();var result = client.BeginConnect("remotehost", this.Port, null, null);var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(1));if (!success){ throw new Exception("Failed to connect.");}// we have connectedclient.EndConnect(result);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)