Windows窗体ComboBox导致间歇性的System.AccessViolationException

时间:2011-05-31 09:28:19

标签: c# winforms exception-handling combobox .net-2.0

一些背景故事:

我搜索了stackoverflow和Google,以找出这个特殊异常的起源。

我们有一个Windows窗体(C#,. NET 2.0)应用程序偶尔会抛出一个System.AccessViolationException(下面的堆栈跟踪)。 Windows XP(SP3)和Windows Vista(SP2)都发生了异常。从用户输入,我们已经确定当更改ComboBox的选定索引时发生异常。

ComboBox是标准的Windows窗体组件,它包含在继承System.Windows.Forms.UserControl的自定义控件中。

我的主要问题是:

此例外的来源是什么?

  • 是否来自.NET框架中的一些内部错误?
  • 可能是导致它的SelectedIndexChanged事件上调度的代码吗?

有关stackoverflow的相关主题:

堆栈跟踪:

Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Type: System.AccessViolationException

   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
   at System.Windows.Forms.Control.DefWndProc(Message& m)
   at System.Windows.Forms.Control.WmCommand(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ComboBox.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

2 个答案:

答案 0 :(得分:1)

当我使用.net 2.0 WinForms时,我也遇到了这些问题。我似乎记得微软为此发布了一个Hotfix。我用Google搜索并找到了这两个。你可以尝试一下。

http://support.microsoft.com/kb/923028

http://support.microsoft.com/kb/971030

此外,您是否安装了.NET 2.0的所有Service Pack?

答案 1 :(得分:-1)

不要让它有机会超载内存,处理所有新的和未使用的项目/控件 不要常常在列表框中添加/删除对象,通常是在线程操作期间。

如果您不清除内存,则会出现GDI问题。

发生组合框异常,它可能与选择项有关,无论该项是否存有文本或整数。 文本必须是文本,整数必须是整数。