我写了一个UDP接收程序,用线程启动!
现在我关闭时总提示有死循环或递归无法关闭
如何解决
thread = new Thread(new ThreadStart(Connection));
                thread.Start();public void Connection()
{
            remoteIPEndPoint = new IPEndPoint(IPAddress.Any, 3300);            udpReceive = new UdpClient(remoteIPEndPoint);            eip = new IPEndPoint(IPAddress.Any, 3300);            while (t)
            {
                try
                {
                    receiveBytes = udpReceive.Receive(ref eip);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "接收错误");
                    return;
                }
             }
}

解决方案 »

  1.   

    可以设一个bool做一个判断,在time控件的start方法里加停止线程的方法
      

  2.   

    你这里哪有递归
    让t=false 还在继续循环?
      

  3.   

    System.Threading.ManualResetEvent allthread = new System.Threading.ManualResetEvent(false);
     allthread.Close();
    终止所有线程
      

  4.   

    你在终止程序时有没有让t=false?如果让t=false了,还出现这个情况的话,估计不是这段代码的问题。。
      

  5.   


    还是不行
    出现"未处理的“System.StackOverflowException”类型的异常出现在 未知模块 中"
      

  6.   


    可不可以说下,你关闭程序时,有没有把t=false?
      

  7.   

    while(!stopped)
    {
     ....
    }
    voud Stop()
    {
       stopped = true;
    }