|
比如这名Socket clientsocket = Servertsocket.Accept();当服务器绑定ip,端口后等待客户端连接,如果此时我要结束任务要怎么实现???
Task taskaccept = new Task(() =>
{
while (true)
{
Socket clientsocket = Servertsocket.Accept();
IPEndPoint endPoint = clientsocket.RemoteEndPoint as IPEndPoint;
if (Form1.frm1.textBox2.InvokeRequired)
{
Form1.frm1.textBox2.Invoke(action = () =>
{
Form1.frm1.textBox2.Text += endPoint.Address + "[" + endPoint.Port + "]连接成功" + "\r\n";
});
}
else
{
Form1.frm1.textBox2.Text += endPoint.Address + "[" + endPoint.Port + "]连接成功" + "\r\n";
}
}
}, cts1.Token);
}
|
|