OpenFileDialog限制内存可用

时间:2012-03-30 07:48:26

标签: c# .net out-of-memory openfiledialog readfile

执行以下代码时:

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;
}

我面临着一种奇怪的内存行为:内存使用率一直快速上升到710 MB,然后它开始逐字节地上下浮动接近710MB,最后我得到一个OutOfMemoryException。

但是,如果我在没有OpenFileDialog的情况下运行代码,只需对文件路径进行硬编码:

string filename = "_complete_file_path_here";
//create a new Thread and read the file.

它可以毫无问题地运行:内存上升到840 MB,没有请求,文件也能正确读取。

任何想法或反馈?

1 个答案:

答案 0 :(得分:0)

这种问题可能是由于shell扩展错误造成的。使用Process Explorer或调试器输出来检查在使用“文件打开”对话框时加载到进程中的DLL。如果您发现任何可疑内容,请尝试卸载相关软件。 (打印机出于某些原因通常是罪魁祸首。)

原因是文件打开对话框加载了Windows资源管理器外壳扩展,不幸的是许多第三方扩展程序都有错误。

相关问题