2014-02-20 40 views
0

在調試應用程序時,我發現MessageBox.Show沒有顯示一些奇怪的行爲。要重現,請使用以下內容並運行它。MessageBox.Show在調試時不顯示異步方法時

它將按預期工作,顯示消息框。

現在在DoSomething中放置一個斷點並運行。 MessageBoxes不會顯示!

現在刪除async關鍵字,它再次按預期工作。

這是怎麼回事?我有一個應用程序執行通常的確認對話框,但它們在調試過程中被跳過。我最終將其追溯到async關鍵字,但這對我而言並沒有任何意義,因爲它爲什麼會出現。也許是調試器中的一個錯誤。

private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { 
     DoSomething(); 
    } 

    public async void DoSomething() { 
     MessageBox.Show("Starting"); 
     ShowMessageBox(); 
     MessageBox.Show("In DoSomething()"); 


    } 

    public void ShowMessageBox() { 
     MessageBox.Show("In ShowMessageBox"); 
    } 
+0

異步方法的完成事件在哪裏? – Sajeetharan

回答

0

這似乎是Visual Studio的問題。