2012-10-07 187 views
1

可能重複:
C#, WPF - OpenFileDialog does not appearOpenFileDialog.ShowDialog()凍結應用程序C#

我試圖讓從約翰·亨特的指南,以C#的 「JDEdit」 應用程序和麪向對象的。不過,我像他一樣輸入了所有代碼,每當我嘗試使用ShowDialog()時,我的應用程序都凍結了。我沒有收到任何編譯器投訴,所以我不知道發生了什麼。

這是我試圖實現的方法。檢查條件時會凍結。我認爲該計劃的其他部分不應該有必要發佈。

private void Open() { 

    // still working 

    if (ofd.ShowDialog() == DialogResult.OK) { 

     // never makes it here 

     string filename = ofd.FileName; 
     Console.WriteLine("Open: {0}", filename); 
     textArea.TextChanged -= new EventHandler 
      (this.TextArea_TextChanged); 
     textArea.LoadFile(filename); 
     textArea.TextChanged += new EventHandler 
      (this.TextArea_TextChanged); 
     saveRequired = false; 
     this.Text = title + ": " + filename; 
    } 
} 

謝謝!

+0

您是否嘗試加載文件? – Lior

+0

我想我應該補充說,對話框永遠不會打開,所以我不能點擊任何東西,我認爲它可能是該帖子的副本。我正在檢查它,試圖找到解決方案。 – will

+0

對不起,重複的問題,沒有看到那一個。上面添加[STAThread]主要修復它。 – will

回答

1

在上面添加[STAThread] Main修復了這個問題。