2013-01-07 52 views
0

我一直在駕駛自己的堅果試圖找出今天這一個。我一直在使用FileSystemWatcher一段時間來捕獲文件更改。我最初在framework 3.5上的一個項目被移動到4.0,以利用一些EF的東西,這似乎影響了Visual Studio如何讓我調試利用FileSystemWatcher的代碼。下面是我遇到的問題的一個小例子(見watcher_Changed):FileSystemWatcher阻止調試器捕獲異常

class Program 
{ 
    static void Main(string[] args) 
    { 
     FileSystemWatcher watcher = new FileSystemWatcher(@"C:\inputFolder\"); 

     watcher.Changed += new FileSystemEventHandler(watcher_Changed); 
     watcher.NotifyFilter = NotifyFilters.LastAccess 
      | NotifyFilters.LastWrite 
      | NotifyFilters.FileName 
      | NotifyFilters.DirectoryName; 

     Console.WriteLine("Ready"); 

     watcher.EnableRaisingEvents = true; 
     Thread.Sleep(System.Threading.Timeout.Infinite); 
    } 

    static void watcher_Changed(object sender, FileSystemEventArgs e) 
    { 
     //This exception here (just an example), does not get sent to the debugger, rather it goes to the 
     //console and then the application exits 
     throw new ArgumentException(); 
    } 
} 

代碼將始終貼近我折騰的ArgumentException到控制檯後。這在更復雜的場景中對我造成了一些主要的調試問題。

任何想法?

回答

0

我想這是因爲Visual Studio沒有配置爲在拋出System.ArgumentException時中斷,但是當它是用戶處理的時候。由於異常發生在由FileSystemWatcher創建的線程中,因此它可能沒有任何一種頂級異常處理程序。

要更改調試設置,請轉到Debug \ Exceptions,然後展開Common Language Runtime Exceptions並搜索該例外。或者使用Find...按鈕。然後確保勾選了「Thrown」複選框。被警告你可能不想正常使用這個選項,因爲許多應用程序可能會正常處理異常。

+0

謝謝,我認爲幫助!我能夠通過兩種方式解決它:1)從調試器設置中刪除'只是我的代碼'設置2)檢查調試 - >異常下的所有拋出的項目 – yabbi