尝试读取或写入受保护的内存,Resources.Image [英] Attempted to read or write protected memory , Resources.Image

查看:67
本文介绍了尝试读取或写入受保护的内存,Resources.Image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!



我开发C#,manged代码,IDE vs2010。



我收到了以下例外:



尝试读取或写入受保护的内存。这通常表明其他内存已损坏


当我尝试从资源更改按钮图像时,我收到了此错误。



代码:



statusButton.Image = Resources.Status_Ok;







statusButton.Image = Resources。 Status_Fail;





异常不会一直出现!!。



命令由timer [System.Timers.Timer]获取。





它让我发疯...... br $>


谢谢!

MAK

Hello!

I develope in C# , manged code ,IDE vs2010.

I received the follow exception:

"Attempted to read or write protected memory.this is often indication that other memory is corrupt"

I recived this error when I try to change button image from resources.

code :

statusButton.Image=Resources.Status_Ok;

Or

statusButton.Image=Resources.Status_Fail;


The exception is not appear all the time!!.

The command is fetch by timer [System.Timers.Timer].


it's make me crazy ....

Thanks!
M.A.K

推荐答案

首先将两张图片加载到Load事件中的类级变量,并使用它们在计时器Tick事件中设置按钮图像 - 在th那一刻,你每次设置它时都会创建新的图像,这可能是问题。
Start by loading the two Images into class level variables in the Load event, and use those to set your button image in the timer Tick event - at the moment, you are creating new images each time you set it which may be the problem.


它只是说资源没有修改限制。

你只要图像在资源中,就不允许这样做。

尝试将其复制到变量中。
It simply say that resources are off limit for modifications.
You are not allowed to do this as long as the image is in the resources.
Try to copy it in a variable.


这篇关于尝试读取或写入受保护的内存,Resources.Image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆