首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

dataGridView 应用报错:AccessViolationException,尝试读取或写入受保护的内存

2013-06-25 
dataGridView 使用报错:AccessViolationException,尝试读取或写入受保护的内存vs2010,xp sp3的系统,新建一

dataGridView 使用报错:AccessViolationException,尝试读取或写入受保护的内存
vs2010,xp sp3的系统,新建一个winform窗口项目后在窗体上加一个dataGridView就会报这个错误。没使用其它任何的组件。



未处理 System.AccessViolationException
  Message=尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
  Source=System.Drawing
  StackTrace:
       在 System.Drawing.SafeNativeMethods.Gdip.GdipDrawRectangleI(HandleRef graphics, HandleRef pen, Int32 x, Int32 y, Int32 width, Int32 height)
       在 System.Drawing.Graphics.DrawRectangle(Pen pen, Int32 x, Int32 y, Int32 width, Int32 height)
       在 System.Drawing.Graphics.DrawRectangle(Pen pen, Rectangle rect)
       在 System.Windows.Forms.DataGridView.PaintBorder(Graphics g, Rectangle clipRect, Rectangle bounds)
       在 System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)
       在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
       在 System.Windows.Forms.Control.WmPaint(Message& m)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.DataGridView.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 WindowsFormsApplication2.Program.Main() 位置 E:\cjing_project\WindowsFormsApplication2\WindowsFormsApplication2\Program.cs:行号 18
       在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)


       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 



详细错误截图:

dataGridView 应用报错:AccessViolationException,尝试读取或写入受保护的内存

dataGridView 应用报错:AccessViolationException,尝试读取或写入受保护的内存
DataGridView 内存
[解决办法]
估计是你直接在工作线程中直接去操作DataGridView造成的,你有没有用Invoke/BeginInvoke委托?

热点排行