2013-07-05 47 views
0

我有以下代碼。任何人都可以告訴我,ut,c2實例會發生什麼?他們會不會長時間被垃圾收集而徘徊?我問的原因是,在關閉所有窗口(包括執行此代碼的窗口)之後,Visual Studio調試器仍處於打開狀態(我正在以調試模式運行它)。 如果我沒有在Class2的Initializer()方法中引發異常,調試器將關閉所有窗口後關閉。VS調試器不關閉

下面是由代碼

namespace Test 
{ 
    public class Class1 
    { 

    private ICommand testCommand; 
    public ICommand TestCommand 
    { 
     get 
     { 
     return updCommand ?? (updCommand = new DelegateCommand(() => 
     { 
      int nStatus = 0; 
      Class2 c2 = new Class2(); 
      nStatus = c2.InitStatus; 
      if (nStatus == 0) 
      { 
      c2.doSth() 
      } 
      System.Windows.MessageBox.Show("Return status = " + nStatus.ToString()); 
      c2 = null; 
     } 
     )); 
     } 
    } 
    } 

    public class Class2 
    { 
    Utilities ut = new Utilities(); 
    public int InitStatus { get; set; } 

    public Dbupdate() 
    { 
     Initializer(); 
    } 
    private void Initializer() 
    { 
     try 
     { 
     throw new Exception("just test"); 
     } 
     catch (Exception ex) { ErrHandler("Initializer(): " + ex.Message); InitStatus = -100; } 
    } 

    private void doSth() 
    { 
     ut.doWhateve(); 
    } 
    } 
} 
+0

什麼是Application.ShutdownMode的應用程序? – RQDQ

+0

我在哪裏查找Application.ShutdownMode的應用程序? – Shawn

+0

它沒有在app.xaml中定義所以它必須是默認的OnLastWindowClose。 – Shawn

回答

0

想通了。我實例化了一個窗口,但在拋出異常之前沒有關閉。