我目前正在使用Windows窗体应用程序,它会在按钮单击时打开一个新窗口。当我关闭第二个窗口时,我间歇地得到以下异常,而第二个窗口又会导致我的应用程序崩溃。
应用程序:Manager.exe Framework版本:v4.0.30319描述: 由于未处理的异常,该过程终止。例外 信息:System.AccessViolationException Stack:at System.Drawing.SafeNativeMethods + Gdip.GdipDrawImageRectRectI(System.Runtime.InteropServices.HandleRef,System.Runtime.InteropServices.HandleRef,Int32,Int32,Int32,Int32, Int32,Int32,Int32,Int32,Int32, System.Runtime.InteropServices.HandleRef,DrawImageAbort, System.Runtime.InteropServices.HandleRef)at System.Drawing.Graphics.DrawImage(System.Drawing.Image对象, System.Drawing.Rectangle,Int32,Int32,Int32,Int32, System.Drawing.GraphicsUnit,System.Drawing.Imaging.ImageAttributes, DrawImageAbort,IntPtr)at System.Drawing.Graphics.DrawImage(System.Drawing.Image对象, System.Drawing.Rectangle,Int32,Int32,Int32,Int32, System.Drawing.GraphicsUnit,System.Drawing.Imaging.ImageAttributes)
在 System.Windows.Forms.ControlPaint.DrawBackgroundImage(System.Drawing.Graphics, System.Drawing.Image,System.Drawing.Color, System.Windows.Forms.ImageLayout,System.Drawing.Rectangle, System.Drawing.Rectangle,System.Drawing.Point, System.Windows.Forms.RightToLeft)at System.Windows.Forms.Control.PaintBackground(System.Windows.Forms.PaintEventArgs, System.Drawing.Rectangle,System.Drawing.Color,System.Drawing.Point) 在 System.Windows.Forms.Control.PaintBackground(System.Windows.Forms.PaintEventArgs, System.Drawing.Rectangle)at System.Windows.Forms.Control.OnPaintBackground(System.Windows.Forms.PaintEventArgs) 在 System.Windows.Forms.ScrollableControl.OnPaintBackground(System.Windows.Forms.PaintEventArgs) 在 System.Windows.Forms.Control.PaintWithErrorHandling(System.Windows.Forms.PaintEventArgs, Int16)at System.Windows.Forms.Control.WmEraseBkgnd(System.Windows.Forms.Message ByRef)at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)at System.Windows.Forms.ScrollableControl.WndProc(System.Windows.Forms.Message ByRef)at System.Windows.Forms.Control的+ ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)at System.Windows.Forms.Control的+ ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)在System.Windows.Forms.NativeWindow.Callback(IntPtr,Int32, IntPtr,IntPtr)at System.Windows.Forms.UnsafeNativeMethods.IntBeginPaint(System.Runtime.InteropServices.HandleRef, PAINTSTRUCT ByRef)at System.Windows.Forms.Control.WmPaint(System.Windows.Forms.Message ByRef)at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)at System.Windows.Forms.ScrollableControl.WndProc(System.Windows.Forms.Message ByRef)at System.Windows.Forms.Control的+ ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)at System.Windows.Forms.Control的+ ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)在System.Windows.Forms.NativeWindow.Callback(IntPtr,Int32, IntPtr,IntPtr)at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef)
在 System.Windows.Forms.Application + ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr的, Int32,Int32)at System.Windows.Forms.Application + ThreadContext.RunMessageLoopInner(的Int32, System.Windows.Forms.ApplicationContext)at System.Windows.Forms.Application + ThreadContext.RunMessageLoop(的Int32, System.Windows.Forms.ApplicationContext)at System.Windows.Forms.Application.Run(System.Windows.Forms.Form)at Manager.Program.Main()
我通常能够在白天没有任何问题地打开和关闭,但是如果我让程序一夜之间运行并且尝试在早上打开第二个窗口,那么当我试图关闭窗口时我会得到这个例外。当我第一次开始运行应用程序时,此异常会更频繁地被抛出。
是否有人看过这个例外或者知道如何修复它?我在网上搜索了很多,试图找到答案,但一直找不到适用的答案。