Attempted to read or write protected memory from Resources.Image

时间:2015-07-28 15:47:16

标签: c#

In the background I use a DLL for pooling data from PCI-e bus via DMA. If I run only the DLL without to update the status I can run for hours.

I receive 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 does not appear all the time!

The command is fetch by timer (System.Timers.Timer).

1 个答案:

答案 0 :(得分:0)

听起来你正试图从后台进程(即你的计时器)向你的UI加载一些东西,它总是试图锁定你的主线程来绘制。您需要控制该锁定,否则您将遇到锁定问题 - 尤其是在您与应用程序交互或长时间运行主线程操作时。

查看后台工作线程以运行您的DLL - http://www.codeproject.com/Articles/841751/MultiThreading-Using-a-Background-Worker-Csharp - 因为这可能会解决您的问题。