日期:2014-05-17  浏览次数:20734 次

大家帮我解决一个关于winform问题,至于关闭窗体后仍显示调试状态。

这个是执行窗体
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;


namespace 客户端
{
    class 服务器
    {
        //声明一个int类型常量存放端口号
        private const int listenPort = 11000;
        public string strInfo=null;
        public bool boo = true;
        public void StartListener()
        {
            

            //实例化UdpClient类,接收值为端口号
            UdpClient listener = new UdpClient(listenPort);
            //实例化类IPEndPoint,用listenPort的端口来接收来自所有ip的信息
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
            try
            {
                //写一个死循环监控
                while (boo)
                {
                    //声明一个byte类型数组,存放接收过来的值。
                    byte[] bytes = listener.Receive(ref groupEP); //ref 关键字使参数按引用传递
                    //获得发信人的IP
                    string strIP = "信息来自" + groupEP.Address.ToString();
                    //获得信息通过gb2312编码转化为汉字
                    strInfo = Encoding.GetEncoding("gb2312").GetString(bytes, 0, bytes.Length);

                    //return strInfo;
                    //MessageBox.Show(strInfo, strIP);
                }
            }
            catch (Exception e)
            {
                strInfo = e.ToString();
      &nb