【问题标题】:Pressing "OK" on an OpenFileDialog takes a long time在 OpenFileDialog 上按“确定”需要很长时间
【发布时间】:2015-11-12 09:07:05
【问题描述】:

我想通过文件对话框从共享中选择一个文件名(例如OpenFileDialog)。

在对话框上单击“确定”需要很长时间(在我的情况下最多 20 秒)。如果我在按“确定”之前导航到共享文件夹,这也是正确的。似乎按下“确定”会触发下载或类似的操作。

  • 如何加快在OpenFileDialog 上按“确定”的速度。 (也许它确实会触发下载,我可以告诉它不要触发,等等)
  • 我应该使用另一个对话框来选择文件吗? (可能OpenFileDialog 暗示文件已打开并且有一个选择对话框。)

这是我的代码:

var openFileDialog1 = new OpenFileDialog()
{
  InitialDirectory = "c:\\",
  Filter = "txt files (*.txt)|*.tca|All files (*.*)|*.*",
  FilterIndex = 2,
  RestoreDirectory = true,
};

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
  MessageBox.Show(openFileDialog1.FileName);
}

这是回溯,而对话框正忙:

  [Managed to Native Transition] 
  System.Windows.Forms.dll!System.Windows.Forms.FileDialog.RunDialogVista(System.IntPtr hWndOwner) + 0x75 Bytes       
  System.Windows.Forms.dll!System.Windows.Forms.FileDialog.RunDialog(System.IntPtr hWndOwner) + 0x55 Bytes        
  System.Windows.Forms.dll!System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window owner) + 0x1cb Bytes    
  System.Windows.Forms.dll!System.Windows.Forms.CommonDialog.ShowDialog() + 0x7 Bytes     
> TestCases.exe!TestCases.Program.SelectFile() Line 39 + 0xa Bytes
  TestCases.exe!TestCases.Program.Main() Line 24 + 0x5 Bytes

【问题讨论】:

  • 您是否在发布和调试模式下都进行了实验?
  • @Thomas 我都测试过,据我所知没有区别。
  • 你用WiFi浏览网络吗?以太网?您在浏览网络时或仅使用 OpenFileDialog 时是否看到此行为?
  • 不,它不会自动下载文件。 OpenFileDialog 只是 Windows 对话框的一个薄包装——它几乎没有任何代码。至于 Windows 对话框,嗯,它做了很多事情。例如,它可以为您取消引用快捷方式(这可能需要几秒钟,但 20 秒是很长的时间)。如果在对话框“挂起”时中断调试器,你会看到什么?您是在 Windows API 中还是在您的代码中?
  • 我从位于我们网络内部的共享服务器读取整个文件没有问题。使用 OpenFileDialog。可能是您要查找的文件位于 ftp 上还是其他需要某种身份验证的地方?

标签: c# wpf


【解决方案1】:

尝试this 链接以获得解决方案。其他人也有同样的问题。解释旧的快捷方式/网络快捷方式可能会对此产生影响。

希望对你有所帮助。

【讨论】:

    猜你喜欢
    • 2015-12-28
    • 1970-01-01
    • 2013-09-07
    • 2020-08-26
    • 2014-10-09
    • 2012-11-26
    • 2019-12-27
    • 2017-10-22
    • 2020-11-15
    相关资源
    最近更新 更多