编写了一个c#程序,但运行的时候,窗体界面一闪而过,就只剩下后台进程了,为什么会这样? 40
privatevoidForm1_Load(objectsender,EventArgse){//创建后台监听线程Threadlistened=newThread(new...
private void Form1_Load(object sender, EventArgs e)
{
//创建后台监听线程
Thread listened = new Thread(new ThreadStart(getlisten));
listened.IsBackground = true;
listened.Start();
}
void getlisten()
{
promopt.Items.Add("正在等待连接…………");
Socket newsocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 8080);
newsocket.Bind(iep);
promopt.Items.Add("正在连接…………");
newsocket.Listen(5);
newsocket.BeginAccept(new AsyncCallback(AcceptConn), newsocket);
}
void AcceptConn(IAsyncResult iar)
{
Socket orig = (Socket)iar.AsyncState;
Client = orig.EndAccept(iar);
history.Items.Add("来自:" + Client.RemoteEndPoint.ToString());
Thread recive = new Thread(new ThreadStart(ReciveData));
recive.IsBackground = true;
recive.Start();
}
没人了吗?。。还有没有其他答案。。 展开
{
//创建后台监听线程
Thread listened = new Thread(new ThreadStart(getlisten));
listened.IsBackground = true;
listened.Start();
}
void getlisten()
{
promopt.Items.Add("正在等待连接…………");
Socket newsocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 8080);
newsocket.Bind(iep);
promopt.Items.Add("正在连接…………");
newsocket.Listen(5);
newsocket.BeginAccept(new AsyncCallback(AcceptConn), newsocket);
}
void AcceptConn(IAsyncResult iar)
{
Socket orig = (Socket)iar.AsyncState;
Client = orig.EndAccept(iar);
history.Items.Add("来自:" + Client.RemoteEndPoint.ToString());
Thread recive = new Thread(new ThreadStart(ReciveData));
recive.IsBackground = true;
recive.Start();
}
没人了吗?。。还有没有其他答案。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |