jinuo

求助 .net 进程问题

暂放到首页
winform 程序包括一个窗体
当窗体登录时启动了一个新线程TcpListener,进行监听代码如下
private bool isListen = false//是否进行监听


private void Form1_Load() 
{
   isListen 
= true
   Thread  thread1 
= new Thread(new ThreadStart(StartListen));
   thread1.Start();
}



public void StartListen()
        
{
            IPHostEntry iphostInfo 
= Dns.Resolve(Dns.GetHostName());
            IPEndPoint localEp 
= new IPEndPoint(iphostInfo.AddressList[0],this.LocalPort);
            TcpListener tcplistener 
= new TcpListener(localEp);
            tcplistener.Start();
            
while(isListen)
            
{
                TcpClient client 
= tcplistener.AcceptTcpClient();
                NetworkStream ns 
= client.GetStream();
                
try
                
{
                    
if(ns.CanWrite)
                    
{
                        
byte[] by = Encoding.ASCII.GetBytes("OK");
                        ns.Write(by,
0,by.Length);
                    }

                }

                
catch(SocketException se)
                
{
                    Log.WriteLog(
"网络通信"+se.Message.ToString());
                    MessageBox.Show(
this,"会员管理系统出现异常,请重新启动!","系统提示");
                }

                ns.Close();
                client.Close();
            }

            tcplistener.Stop();            
        }

private void Form1_Closing() //调用Form1 Closing 事件
{
   isListen 
= false;
}

当Form1_Closing() 中将私有变量 isListen = false;原本以为该线程会退出,
当窗体调用Close() 后,窗体消失了,但该应用程序一直停留在内存中,请问如何停止该进程
 

http://www.uoms.net


posted on 2005-02-23 00:36  skywarps  阅读(1344)  评论(7编辑  收藏  举报

导航