【发布时间】:2013-12-22 20:35:35
【问题描述】:
我们正在使用 C# 创建一个漫画书应用程序,并像往常一样在启动时创建一个 mainForm,然后当按下“1”键时,会弹出一个名为 detailForm 的新表单,显示所选漫画书的详细信息。如果您在 detailForm 上再次按“1”,还会创建第三种表单,这将打开另一个名为 ComicForm 的表单,显示实际的漫画书。
当您按“1”从 mainForm 转到 detailForm,然后立即按“2”返回 mainForm 时,我们的问题就开始了。当你这样做时,我们会得到这些异常中的任何一个。它不一致,可能会显示 System.AccessViolationException 或 System.Runtime.InteropServices.SEHException。
我们在 detailForm 上有一个 COM 对象,它显示了一个特定于每个漫画人物的 youtube 视频。
每次构建项目时都会抛出2个警告:
1> COM Reference 'AcroPDFLib' is the interop assembly for ActiveX control 'AxAcroPDFLib' but was marked to be linked by the compiler with the /link flag. This COM reference will be treated as a reference and will not be linked.
1> COM Reference 'ShockwaveFlashObjects' is the interop assembly for ActiveX control 'AxShockwaveFlashObjects' but was marked to be linked by the compiler with the /link flag. This COM reference will be treated as a reference and will not be linked.
运行这段代码后,每次都会崩溃:
private void detailForm_KeyDown_1(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.D2)
{
player.controls.stop();
this.Close();
}
if (e.KeyData == Keys.D1)
{
this.Close();
player.controls.stop();
ComicForm comicShow = new ComicForm(newComic);
comicShow.Show();
comicShow.Focus();
}
}
崩溃后,它在 Program.cs 中突出显示,但实际上并没有运行它:
Application.Run(new MainForm());
【问题讨论】:
-
您找到解决方案了吗?
标签: c# winforms exception com event-handling