AcceptTcpClient 添加后窗体不显示

fordawn 2013-05-05 03:57:45

private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.Text+="Server\n";
IPAddress ip=new IPAddress(new byte[] {127, 0, 0, 1});
TcpListener listener=new TcpListener(ip, 8500);

listener.Start();
richTextBox1.Text+="Listen start ...\n";

while(true) {
TcpClient remoteClient=listener.AcceptTcpClient();
richTextBox1.Text+=string.Format("Client Connected! {0} --> {1}",
remoteClient.Client.LocalEndPoint, remoteClient.Client.RemoteEndPoint);
}
}


如果去掉


while(true) {
TcpClient remoteClient=listener.AcceptTcpClient();
richTextBox1.Text+=string.Format("Client Connected! {0} --> {1}",
remoteClient.Client.LocalEndPoint, remoteClient.Client.RemoteEndPoint);
}

就是好使的,加上以后运行或者调试窗口不显示,任务管理器里有进程,把while拿掉也是一样的,求解。
...全文
62 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fordawn 2013-05-05
  • 打赏
  • 举报
回复
咋弄呢 。。
本拉灯 2013-05-05
  • 打赏
  • 举报
回复
主线程被占用了。请另开一个线程来运行

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧