我有一個打開OpenFileDialog的按鈕。當我編譯應用程序時,首次運行它,按下按鈕,選擇文件,然後按下接受對話框按鈕,等待大約一分鐘,然後將選定的文件添加到我的列表框中。C# - OpenFileDialog太慢,只有第一次按下確定
如果我關閉應用程序,重新啓動它並執行與上面相同的操作,那麼所有操作都可以快速正常進行。從那以後它總是工作得很快。這只是我編譯後第一次運行它,因爲它太慢了。
代碼摘錄如下。對話框有什麼問題?爲什麼它第一次緩慢運行?謝謝。
void ButtonAddClick(object sender, EventArgs e)
{
this.openFileDialog.FileName = String.Empty;
this.openFileDialog.InitialDirectory = this.openPath;
if (this.openFileDialog.ShowDialog() == DialogResult.OK)
{
foreach (string file in this.openFileDialog.FileNames)
{
if (!File.Exists(file))
{
this.ShowStatus("Error occured selecting file " + Path.GetFileName(file));
}
else if (!this.listBoxFiles.Items.Contains(file))
{
this.listBoxFiles.Items.Insert(0, file);
}
else{
this.ShowStatus("File " + Path.GetFileName(file) + " already selected");
}
}
}
if (this.listBoxFiles.Items.Count > 0)
{
this.openPath = Path.GetDirectoryName(this.listBoxFiles.Items[0].ToString());
this.listBoxFiles.Enabled = true;
this.buttonClear.Enabled = true;
this.buttonFolder.Enabled = true;
}
}
你在VS中運行應用程序,調試嗎?您是否嘗試編譯然後手動從發佈文件夾運行應用程序以查看是否存在相同的問題? – Mikanikal
我從哪裏運行它並不重要,也不管它處於調試模式還是發佈模式。我使用SharpDevelop。我應該只添加openfilesdialog是第一次慢,其他任何對話框都是runnig很好。 – linuxoid
在延遲一分鐘的時間內進入調試器,看看你的線程在做什麼。 –