当前位置: 代码迷 >> C# >> !程序跑了1个小时之后出现大红叉,然后就死了
  详细解决方案

!程序跑了1个小时之后出现大红叉,然后就死了

热度:315   发布时间:2016-05-05 02:47:29.0
求助!!程序跑了1个小时之后出现大红叉,然后就死了

还可能会直接报错,错误信息如下
未处理 System.Runtime.InteropServices.ExternalException
  Message=GDI+ 中发生一般性错误。
  Source=System.Drawing
  ErrorCode=-2147467259
  StackTrace:
       在 System.Drawing.Image.SelectActiveFrame(FrameDimension dimension, Int32 frameIndex)
       在 System.Drawing.ImageAnimator.ImageInfo.UpdateFrame()
       在 System.Drawing.ImageAnimator.UpdateFrames()
       在 System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
       在 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.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)
       在 FiveAxisSimulator.Program.Main()
       在 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: 

小弟新手,折腾了好几天了,实在搞不定
------解决思路----------------------
看你异常里面有Thread,你是不是跨线程操作主线程控件了?而且还是用的最粗暴的设置全局属性不检测是否跨线程操作控件?你得找哪些地方用了线程,然后看哪些会频繁更新控件,还有哪些可能不进行dispose的
------解决思路----------------------
引用:
看你异常里面有Thread,你是不是跨线程操作主线程控件了?而且还是用的最粗暴的设置全局属性不检测是否跨线程操作控件?你得找哪些地方用了线程,然后看哪些会频繁更新控件,还有哪些可能不进行dispose的

你猜错了,他这情况多数是内存溢出了,这种情况多数是GDI+整出来的,
他肯定是用了读取图片资源,没有释放或读取的图片格式不正确造成的。
------解决思路----------------------
是的,开始没问题,用上一会儿(有时几小时或者几天)就崩掉,绝大多数是内存溢出了。
------解决思路----------------------
Image.FromFile 就是这句啦,要释放。
  相关解决方案