none
OpenFileDialog is incredibly slow RRS feed

  • Question

  • I display a Microsoft.Win32.OpenFileDialog like this (C#):

    Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog();
    fileDialog.Filter = "Trace files (*.trc)|*.trc|Msg files (*.msg)|*.msg|Both (*.trc, *.msg)|*.trc;*.msg";
    fileDialog.CheckFileExists = true;
    fileDialog.Multiselect = true;
    if (false == fileDialog.ShowDialog())  

        return;  
     
    // Do something 

    My filter defaults to .trc files in the OpenFileDialog's "Files of type:" combo box. If I select a .trc file, processing is instant.

    If I change the file type to 'Both' and select the same .trc file it takes 11+ seconds to hit any code after the Do something comment. The same problem occurs when I use a System.Windows.Forms.OpenFileDialog.

    Any ideas why the response time is so slow only when I change the filter?

    Thanks in advance,

    Bob
    • Moved by CoolDadTx Friday, November 8, 2019 6:17 PM Winforms related
    Wednesday, July 2, 2008 10:12 AM

Answers

  • Probably hasn't got anything to do with the OpenFileDialog. Any virus protection software that might react on certain file types? Any mapped network paths that are not available? Or perhaps the *.msg types need some form of processing when first displayed (like with image files in the explorer when you select to view thumbnails). Maybe you could try to change the msg types to some other extension in the Filter just to see if you get a changed behaviour.

    /Calle

    • Marked as answer by RobASmith Friday, July 4, 2008 8:27 AM
    Friday, July 4, 2008 12:38 AM

All replies

  • Probably hasn't got anything to do with the OpenFileDialog. Any virus protection software that might react on certain file types? Any mapped network paths that are not available? Or perhaps the *.msg types need some form of processing when first displayed (like with image files in the explorer when you select to view thumbnails). Maybe you could try to change the msg types to some other extension in the Filter just to see if you get a changed behaviour.

    /Calle

    • Marked as answer by RobASmith Friday, July 4, 2008 8:27 AM
    Friday, July 4, 2008 12:38 AM
  • Calle,

    Well, it looks like you hit that one on the head!

    When I delete my systems file extension association for .MSG files (which default to Outlook), the problem goes away.

    But now this begs the question: What the heck is going on behind the scenes when I hit the OK button on an OpenFileDialog with a filter set to a file extension associated with a different app?

    Thank you very much! :)

    Bob
    Friday, July 4, 2008 8:25 AM
  • Happy to hear it solved your problem (sort of).

    When you set the OpenFileDialog filter to view the .msg files then some nasty litte background thread is created that does some processing of these files (you could try to open a .trc file in a directory where there are no .msg files to see if this is different). Now you can select your file and close the dialog but until the thread has finished processing your application would seem to hang. I would assume the open file dialog to use the same components for viewing the files as the explorer.

    /Calle
    Friday, July 4, 2008 9:44 AM
  • I had the same problem. What solved it for me was deleting 2 old, invalid shortcuts under Computer that were pointing to webdav url's that no longer exist. After deleting those shortcuts, openFileDialog now returns control to my code very quickly after dismissing.
    Friday, November 11, 2011 7:37 PM
  • For me it went from 5 seconds to 0 when i turned off ShowPlacesList :

                    var dlg = new CommonOpenFileDialog();
                    dlg.Title = "Close faster :D";
                    dlg.IsFolderPicker = true;
                    dlg.AddToMostRecentlyUsedList = false;
                    dlg.AllowNonFileSystemItems = false;
                    dlg.DefaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
                    dlg.EnsureFileExists = false;
                    dlg.EnsurePathExists = false;
                    dlg.EnsureReadOnly = false;
                    dlg.EnsureValidNames = false;
                    dlg.Multiselect = false;
                    dlg.ShowPlacesList = false;
    • Edited by Mamunz Friday, November 8, 2019 5:53 PM
    Friday, November 8, 2019 5:52 PM