我编写的监听程序c# 但是程序运行后一点窗体就会卡死 怎么解决啊 那为大神帮我看看 怎么改
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace 聊天__qq群
{
public partial class Form1 : Form
{
bool done = false;
public Form1()
{
InitializeComponent();
}
private void StartListener()
{
UdpClient listener = new UdpClient(int.Parse(textBox1.Text.ToString().Trim())); //使用UDP协议??
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, int.Parse(textBox1.Text.ToString().Trim())); //任意IP,
try
{
while (!done)//使用永真循环另其一直处于监听状态
{
byte[] bytes = listener.Receive(ref groupEP);
string strIP;
strIP = "信息来自" + groupEP.Address.ToString();//获得发信人的IP
string strInfo = Encoding.GetEncoding("gb2312").GetString(bytes, 0, bytes.Length);//获得信息
MessageBox.Show(strInfo, strIP);
}
}
catch (Exception e)
{ Console.WriteLine(e.ToString()); }
finally { listener.Close(); }
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
&n