winform 通过控件属性导入图片(PNG格式),如按钮背景图片、窗体背景、Label控件的背景图片等。,能正常发布、运行。
但是过一段时间后(约3~5小时之间)会报以下错误,然后界面的图片就消失了,程序也一直报错,重新启动程序后又能正常使用一段时间,具体错误如下:
[2020-05-26 13:44:30.161] TextLogger.Error 1
异常文本
【出现时间】:2020/5/26 13:44:30
【异常方法】:get_Flags
【异常窗口】:System.Drawing.dll
【异常类型】:ArgumentException
【异常信息】:Parameter is not valid.
【堆栈调用】: at System.Drawing.Image.get_Flags()
at System.Windows.Forms.ControlPaint.IsImageTransparent(Image backgroundImage)
at System.Windows.Forms.Control.set_BackgroundImageLayout(ImageLayout value)
at IccOilDS.Fmain.InitializeComponent() in E:\IccOilDS\Fmain.Designer.cs:line 268
at IccOilDS.Fmain..ctor() in E:\IccOilDS\Fmain.cs:line 31
at IccOilDS.Frmckdd.btnPrintCKD_Click(Object sender, EventArgs e) in E:\IccOilDS\Frmckdd.cs:line 927
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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)
【系统版本】:1.0.7450.20051
【总窗体数】:4
【总线程数】:1
[2020-05-26 13:44:35.749] TextLogger.Error 1
异常文本
【出现时间】:2020/5/26 13:44:35
【异常方法】:CheckErrorStatus
【异常窗口】:System.Drawing.dll
【异常类型】:OutOfMemoryException
【异常信息】:Out of memory.
【堆栈调用】: at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.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)
【系统版本】:1.0.7450.20051
【总窗体数】:4
【总线程数】:1
如果你的应用程序涉及各种媒体类型,WPF是一个特别好的选择。
比如,如果您需要合并视频,文档或图像序列之间的动画过渡,或上述任何组合。
如何你需要创建具有类似Web的导航的桌面应用程序,WPF也很棒。
WPF的优势如下:
大概率是代码有问题,建议发一个可复现问题的demo