.NET ImageList有时会损坏

西蒙·克拉夫

使用Winforms .net应用程序时,我们会遇到一个问题,即图像列表有时会损坏。

“损坏”是指图像数量计数错误和/或图像可能已被系统图像替换(例如对话框图标)。

例如,下面的屏幕截图显示了imageInfoCollection显示正确的数字,但是计数显示了错误的数字。

在此处输入图片说明

图像列表位于用户在整个应用程序使用过程中反复打开的表单上。图像列表由窗体上的选项卡控件使用。

仅在打开表单的每5到20次之间的任何时候才会出现此问题。

加载图像列表的代码由设计人员构建,并使用来自资源的图像:

this.imageListCallTakingScreen.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListCallTakingScreen.ImageStream")));
this.imageListCallTakingScreen.TransparentColor = System.Drawing.Color.Transparent;
this.imageListCallTakingScreen.Images.SetKeyName(0, "spinner.png");
this.imageListCallTakingScreen.Images.SetKeyName(1, "recommendation-star.png");
this.imageListCallTakingScreen.Images.SetKeyName(2, "recommendation-star_red.png");
this.imageListCallTakingScreen.Images.SetKeyName(3, "recommendation-star - Transparent.png");
this.imageListCallTakingScreen.Images.SetKeyName(4, "Initialisation_fail16.png");
this.imageListCallTakingScreen.Images.SetKeyName(5, "information_white.png");
this.imageListCallTakingScreen.Images.SetKeyName(6, "Check-icon.png");

除了在designer.cs代码中使用imagelist之外,其他任何地方都不使用imagelist来创建它并将其连接到tab控件(我放入的错误捕获行除外):

在此处输入图片说明

有想法吗?我们被困在这一点上,谷歌并没有出现太多。

汉斯·帕桑特

imageInfoCollection字段正确跟踪ImageList中具有的图像数。Count属性跟踪本机Windows imagelist控件中实际存在的图像数。

There's only one way those values could have a mismatch that I can think of. Your program is leaking GDI object handles. A fairly common problem in Winform apps. That works for quite a while until you reach the operating system quota for such handles, after you've consumed 10,000 of them then Windows stops allowing you to create more. The error checking in the .NET wrapper class is not entirely kosher so this can happen without an exception getting generated. You'll see some more strange painting artifacts when you hit that limit btw.

You can get a basic diagnostic from Task Manager, Processes tab. Use View + Select columns and tick GDI Objects and USER objects. Observe these values while you operate the program like a user would. A steadily climbing value for GDI Objects spells doom. A hint that you are forgetting to use the using statement to dispose System.Drawing objects. And the garbage collector not running often enough to keep you out of trouble. You need to fix this in your code so the counter remains stable at, say, no more than several hundred objects.

稳步攀升USER Objects的值也是一个非常常见的Winforms错误。这是非常致命的,它也会增加GDI对象的数量,而GC无法解决此问题。当您使用Controls.Remove / At()或Controls.Clear()删除代码中的控件,而忘记处置删除的控件对象时,就会发生这种情况。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Quart.Net 有时会运行重叠的任务

来自分类Dev

获取ASP.NET MVC5 WebAPI令牌有时会失败

来自分类Dev

使用ASP.NET状态服务进行会话有时会给页面打乱

来自分类Dev

ContactsRequest.Insert(feedUri,newEntry)有时会失败,并出现System.Net.ProtocolViolationException

来自分类Dev

ASP.NET下载导出的Excel工作表有时会呈现源页面本身

来自分类Dev

DotNetZip使用ASP.NET创建的Zip文件有时会导致网络错误

来自分类Dev

谷歌嵌入地图有时会损坏

来自分类Dev

为什么.NET方法有时会返回通用类型,而不是使用通用类型和类型约束?

来自分类Dev

在asp.net mvc 3中重定向到操作时,登录会话有时会丢失

来自分类Dev

asp.net表单身份验证有时会重定向到default.aspx

来自分类Dev

为什么.NET方法有时会返回通用类型,而不是使用通用类型和类型约束?

来自分类Dev

有时会恢复,有时会结帐

来自分类Dev

TCP / IP IOCP收到的数据有时会损坏-Windows上的Visual C ++

来自分类Dev

为什么Abbyy FineReader Express有时会损坏View?

来自分类Dev

使用FileStream保存图像有时会导致文件损坏

来自分类Dev

来自ttyUSB的Bash读取行有时会损坏字符

来自分类Dev

从内存写入时有时会损坏 TGA 文件

来自分类Dev

mmap有时会失败

来自分类Dev

片段有时会重叠-Android

来自分类Dev

BootStrap映像有时会重叠

来自分类Dev

CIGaussianBlur有时会更改imageOrientation

来自分类Dev

XDomainRequest有时会随机中止

来自分类Dev

Laravel有时会验证规则

来自分类Dev

有时会引发NetworkOnMainThreadException

来自分类Dev

Paramiko有时会引发“ AuthenticationException”

来自分类Dev

自动登录有时会失败

来自分类Dev

自动登录有时会失败

来自分类Dev

CIGaussianBlur有时会更改imageOrientation

来自分类Dev

Ubuntu 14.04有时会冻结

Related 相关文章

  1. 1

    Quart.Net 有时会运行重叠的任务

  2. 2

    获取ASP.NET MVC5 WebAPI令牌有时会失败

  3. 3

    使用ASP.NET状态服务进行会话有时会给页面打乱

  4. 4

    ContactsRequest.Insert(feedUri,newEntry)有时会失败,并出现System.Net.ProtocolViolationException

  5. 5

    ASP.NET下载导出的Excel工作表有时会呈现源页面本身

  6. 6

    DotNetZip使用ASP.NET创建的Zip文件有时会导致网络错误

  7. 7

    谷歌嵌入地图有时会损坏

  8. 8

    为什么.NET方法有时会返回通用类型,而不是使用通用类型和类型约束?

  9. 9

    在asp.net mvc 3中重定向到操作时,登录会话有时会丢失

  10. 10

    asp.net表单身份验证有时会重定向到default.aspx

  11. 11

    为什么.NET方法有时会返回通用类型,而不是使用通用类型和类型约束?

  12. 12

    有时会恢复,有时会结帐

  13. 13

    TCP / IP IOCP收到的数据有时会损坏-Windows上的Visual C ++

  14. 14

    为什么Abbyy FineReader Express有时会损坏View?

  15. 15

    使用FileStream保存图像有时会导致文件损坏

  16. 16

    来自ttyUSB的Bash读取行有时会损坏字符

  17. 17

    从内存写入时有时会损坏 TGA 文件

  18. 18

    mmap有时会失败

  19. 19

    片段有时会重叠-Android

  20. 20

    BootStrap映像有时会重叠

  21. 21

    CIGaussianBlur有时会更改imageOrientation

  22. 22

    XDomainRequest有时会随机中止

  23. 23

    Laravel有时会验证规则

  24. 24

    有时会引发NetworkOnMainThreadException

  25. 25

    Paramiko有时会引发“ AuthenticationException”

  26. 26

    自动登录有时会失败

  27. 27

    自动登录有时会失败

  28. 28

    CIGaussianBlur有时会更改imageOrientation

  29. 29

    Ubuntu 14.04有时会冻结

热门标签

归档