我的代码如下,我在程序的运行过程中开加上本身的一个线程,一共开了三个进程,Dispose如下写,但关闭时总是抛出异常.但是我已经用TRY{}和CATCH{}来处理异常,但还是弹出一个MESSAGEBOX,说是"System.Threading TrhreadAbortException"
请问是什么问题?如何解决?protected override void Dispose(bool disposing)
{
     try
     {
          //关闭线程 
          receivingUdpClient.Close();
          startServer.Abort();           //清除资源 
                
          startDailog.Abort();       }
       catch
       {
                
        };
       if (disposing)
       {
            if (components != null)
            {
                 components.Dispose();
            }
        }
        base.Dispose(disposing);
}异常如下:
System.Threading TrhreadAbortException

解决方案 »

  1.   

    为什么不把这段代码放到Try里面去?
    protected override void Dispose(bool disposing) 

         try 
         { 
              //关闭线程  
              receivingUdpClient.Close(); 
              startServer.Abort();            //清除资源  
                     
              startDailog.Abort(); 
             if (disposing) 
           { 
                if (components != null) 
                { 
                     components.Dispose(); 
                } 
            } 
            base.Dispose(disposing); 
           } 
           catch 
           { 
                     
            }; 
          } 
      

  2.   

    而且如果将
    if (disposing)
    {
          if (components != null)
          {
            components.Dispose();
          }
    }
    base.Dispose(disposing); 放到TRY里,退出不了
      

  3.   

    应该是catch没有处理异常吧..? catch(Exception ex){
       ex.Message
    }
      

  4.   

    thread.Abort()一定会抛出异常的 所以不用try catch就行了
      

  5.   

    try  
         {  
              //关闭线程   
              receivingUdpClient.Close();  
              startServer.Abort();             //清除资源   
                      
              startDailog.Abort();  
             if (disposing)  
           {  
                if (components != null)  
                {  
                     components.Dispose();  
                }  
            }  
            base.Dispose(disposing);  
           }  
           catch(System.Threading.ThreadAbortException)   
           {   
              ...不进行任何操作   
             }
           catch(System.Exception)  
           {  
                      
            };  
      

  6.   

    这不是try catch的问题,是线程的问题!
      

  7.   

    可以在加一个标识.if(bstopclient) 
      return;
     protected override void Dispose(bool disposing)  

           bstopclient=true; 
           if (disposing)  
           {  
                if (components != null)  
                {  
                     components.Dispose();  
                }  
            }  
            base.Dispose(disposing);        
          }  
      

  8.   

    thread.Abort()的异常能处理吗?