【发布时间】:2014-11-01 00:18:26
【问题描述】:
应用程序本身有 2000 行长,因此在此处粘贴代码是没有意义的,尤其是因为其中一位用户收到的异常没有提供任何提示,说明我的代码的哪一部分导致了问题。
顺便说一句,该应用程序只是一个 Windows 窗体,带有一个通常显示不超过几百行数据的 datagridview 和一些其他控件。在它崩溃之前,它加载 datagridview 每一行的单元格的速度非常慢。 (但没有其他用户遇到过同样的问题。)
异常文本如下。有人可以查看它并告诉我这是否是由于我的代码做错了什么或者可能与遇到此异常的用户的特定设置不兼容造成的?
我注意到下面的描述说内存已损坏。是不是表示用户的电脑内存不好???
************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Drawing.SafeNativeMethods.Gdip.GdipDrawRectangleI(HandleRef graphics, HandleRef pen, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Drawing.Graphics.DrawRectangle(Pen pen, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Windows.Forms.ControlPaint.DrawFlatCheckBox(Graphics graphics, Rectangle rectangle, Color foreground, Brush background, ButtonState state)
at System.Windows.Forms.ControlPaint.DrawFlatCheckBox(Graphics graphics, Rectangle rectangle, ButtonState state)
at System.Windows.Forms.ControlPaint.DrawCheckBox(Graphics graphics, Int32 x, Int32 y, Int32 width, Int32 height, ButtonState state)
at System.Windows.Forms.ControlPaint.DrawCheckBox(Graphics graphics, Rectangle rectangle, ButtonState state)
at System.Windows.Forms.CheckedListBox.OnDrawItem(DrawItemEventArgs e)
at System.Windows.Forms.ListBox.WmReflectDrawItem(Message& m)
at System.Windows.Forms.ListBox.WndProc(Message& m)
at System.Windows.Forms.CheckedListBox.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)
【问题讨论】:
-
要么是内存损坏,要么是winforms的bug。
-
内存损坏可能意味着在某个时间点、某处有内存覆盖。应用程序是否在任何地方使用
unsafe代码? -
没有。此应用没有不安全代码。
-
有 2 个选项。要么用户确实有坏的物理内存,要么应用程序在某处使用非托管代码错误地将值写入内存。与内存问题相比,它更有可能是软件问题。异常的调用堆栈是否总是相同的?如果是,那么几乎可以肯定是软件问题。您是否使用任何第三方组件?
-
你修改了自动生成的表单设计器代码吗?