When executing the following code:
OpenFileDialog dialog = new OpenFileDialog();
DialogResult result = dialog.ShowDialog();
string filename = "";
if (result == DialogResult.OK)
{
filename = dialog.FileName;
//create a new Thread and read the file.
}
else
{
return;
}
I'm facing a strange memory behaviour: the memory usage goes up very fast till 710 MB, then it starts floatating byte-by-byte up and down close to 710MB, and finally I get a OutOfMemoryException.
But, if I run the code without the OpenFileDialog, by simply hard-coding the filepath:
string filename = "_complete_file_path_here";
//create a new Thread and read the file.
it will work without any problem: the memory goes up till 840 MB without esitations, and file get read correctly.
Any idea or feedback?
This sort of issue can be caused by a bad shell extension. Use Process Explorer or the debugger output to check what DLLs are loaded into your process when you use the File Open dialog. If you find anything suspicious, try uninstalling the associated software. (Printers are for some reason often a culprit here).
The reason is that the file open dialog loads Windows Explorer shell extensions, and unfortunately many of the third-party ones are buggy.