下面的代码是我悲伤的一个(三个)例子。这是一个简单的 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();
}