下面的代碼是我悲傷的例子之一。這是一個簡單的OpenFileDialog()調用,它會導致程序崩潰。在XP上,如果對話框保持打開幾秒鐘,就會發生崩潰。在Vista上,如果用戶選擇「我的電腦」,則會發生崩潰。在VS2008中,調試器有時會遇到堆棧溢出漏洞。如果我在第一行放置了一個斷點(新...),vshost.exe崩潰。如果我在ShowDialog()行放置了一個斷點,那麼我得到一個FatalExecutionEngineError。如果我沒有使用vshost進行編譯,應用程序將運行到隨機崩潰(如在XP上 - 有一定的時間)。C#中的Stackoverflow/CLR錯誤OpenFileDialog
還有另外兩個打開的對話框打開不同類型的文件,其中三個都具有相同的行爲。類似的代碼在我的其他項目中不顯示相同的行爲。
螺紋公寓是單身。我已經嘗試設置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();
}
+1 - 上下文是必需的。 Stackoverflowexception通常意味着該方法被調用的次數太多。 – keyboardP 2010-01-18 18:46:41
函數正在從窗體設計器生成的代碼中調用。 該代碼是通過單擊按鈕實例化的。我已確認此代碼在代碼庫中僅作爲事件添加一次(函數名稱在代碼庫中只存在兩次 - 一次在設計器代碼中,一次在函數定義中)。 我確定保存文件對話框也會發生同樣的情況。 對話框在崩潰之前大約20秒內保持打開狀態 - 我確認只打開了單個對話框實例。 – user253431 2010-01-18 18:55:16
@unknown,你可以發佈事件連接代碼和updateImageDisplay代碼嗎? – JaredPar 2010-01-18 18:56:10