以下のコードは、私の悲しみの (3 つの) 例の 1 つです。これは、プログラムをクラッシュさせる単純な OpenFileDialog() 呼び出しです。XP では、ダイアログが数秒間開いたままになると、クラッシュが発生します。Vista では、ユーザーが [マイ コンピュータ] を選択するとクラッシュが発生します。VS2008 では、デバッガーが stackoverflowexception をキャッチすることがあります。最初の行 (new ...) にブレークポイントを入れると、vshost.exe がクラッシュします。ShowDialog() 行にブレーク ポイントを配置すると、FatalExecutionEngineError が発生します。vshost なしでコンパイルすると、アプリケーションはランダムにクラッシュするまで実行されます (XP のように、ある程度の時間があります)。
異なる種類のファイルを開く 2 つの開いているダイアログがあり、その 3 つすべてが同じ動作をします。同様のコードは、私の他のプロジェクトでは同じ動作を示しません。
スレッドアパートメントはシングルです。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();
}