3

下面的代码是我悲伤的一个(三个)例子。这是一个简单的 OpenFileDialog() 调用,它会导致程序崩溃。在 XP 上,如果对话框保持打开几秒钟,就会发生崩溃。在 Vista 上,如果用户选择“我的电脑”,就会发生崩溃。在 VS2008 中,调试器有时会捕获 stackoverflowexception。如果我在第一行(new ...)放置一个断点,vshost.exe 就会崩溃。如果我在 ShowDialog() 行设置一个断点,我会得到一个 FatalExecutionEngineError。如果我在没有 vshost 的情况下编译,应用程序将一直运行,直到随机崩溃(就像在 XP 上一样 - 有一些时间)。

还有另外两个打开的对话框可以打开不同类型的文件,这三个都具有相同的行为。类似的代码在我的其他项目中没有显示相同的行为。

线程单元是单一的。我尝试设置 ValidateNames = false。在大多数情况下,调试器正在下降。

OpenFileDialog imageDlg = new OpenFileDialog();
imageDlg.Filter = "All Images|*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.bmp|All Files|*.*|JPEGs (*.jpg)|*.jpg|PNGs (*.png)|*.png|TIFFs (*.tiff)|*.tiff|TIFFs (*.tif)|*.tif|BMPS (*.bmp)|*.bmp";
imageDlg.Title = "Select Scan Image";

if (DialogResult.OK == imageDlg.ShowDialog())
{
    updateImageDisplay();
}

事件处理程序代码:

// 
// setScratchImageButton
// 
this.setScratchImageButton.Location = new System.Drawing.Point(191, 15);
this.setScratchImageButton.Name = "setScratchImageButton";
this.setScratchImageButton.Size = new System.Drawing.Size(26, 23);
this.setScratchImageButton.TabIndex = 8;
this.setScratchImageButton.Text = "...";
this.setScratchImageButton.UseVisualStyleBackColor = true;
this.setScratchImageButton.Click += new System.EventHandler(this.setScratchImageButton_Click);

代码调用

    private void updateImageDisplay()
    {
        if (null != project.srcImage)
        {
            imageDisplay.SizeMode = PictureBoxSizeMode.Normal;
            if (project.srcImage != null)
            {
                imageDisplay.ClientSize = new Size(project.srcImage.Width, project.srcImage.Height);
                imageDisplay.Image = (Image)project.srcImage;
            }
            this.ScratchImage.Text = project.srcImageLocation;
        }
        else
        {
            imageDisplay.Image = null;
            this.ScratchImage.Text = "";
        }
        ImageDisplayPanel.Refresh();
    }
4

2 回答 2

5

在什么情况下调用显示这个对话框的方法?此错误的最可能来源是该事件被多次生成并导致OpenFileDialog向用户显示许多实例。它们可能会被显示在彼此的顶部,看起来只有一个对话框。

编辑

如果只有调试器方案失败,请尝试将隐式函数评估关闭到调试器属性窗口(工具 -> 选项 -> 调试器)。通过调试器查看时,表单上的某个属性可能会导致堆栈溢出。

于 2010-01-18T18:45:20.633 回答
1

我添加到项目中的 DLL 导致堆损坏。症状是奇怪而美丽的崩溃。

于 2010-01-18T23:32:49.237 回答