private EventHandler EventAnimator
        {
            get
            {
                if (_eventAnimator == null)
                    _eventAnimator = delegate(object sender, EventArgs e)
                    {
                      Invalidate(ImageRectangle);  //尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
                    };
                return _eventAnimator;
            }
        }
求高人指点迷津。

解决方案 »

  1.   

            public void InsertControl(Control control)
            {
                if (control != null)
                {
                    ILockBytes bytes;
                    IStorage storage;
                    IOleClientSite site;
                    Guid guid = Marshal.GenerateGuidForType(control.GetType());
                    NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out bytes);
                    NativeMethods.StgCreateDocfileOnILockBytes(bytes, 0x1012, 0, out storage);
                    IRichEditOle.GetClientSite(out site);//问题所在
                    REOBJECT lpreobject = new REOBJECT();
                    lpreobject.cp = _richEdit.TextLength;
                    lpreobject.clsid = guid;
                    lpreobject.pstg = storage;
                    lpreobject.poleobj = Marshal.GetIUnknownForObject(control);
                    lpreobject.polesite = site;
                    lpreobject.dvAspect = 1;
                    lpreobject.dwFlags = 2;
                    lpreobject.dwUser = 1;
                    IRichEditOle.InsertObject(lpreobject);
                    Marshal.ReleaseComObject(bytes);
                    Marshal.ReleaseComObject(site);
                    Marshal.ReleaseComObject(storage);
                }
            }
    求高人赐教是不是invalidate()方法读取byte越界了
      

  2.   

    Guid guid = Marshal.GenerateGuidForType(control.GetType());
      NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out bytes);
      NativeMethods.StgCreateDocfileOnILockBytes(bytes, 0x1012, 0, out storage);
    问题都基本存在,
    1.重新编译一下试试,
    2.用了线程,lock公用的变量
    3.外部资源有否正确释放,如:网络,IO ,  要close
    4.注意static变量使用