winform中,页面PrivilegeInfo的构造函数中有:  Form1.R900APP.evtInventoryEPC += new UHFAPI_NET.UHFAPI_NET.InventoryEPCDispacher(ShowInventoryEPC);其中设计到的都在这里:
  public void ShowInventoryEPC(string epc)
        {
            this.txtEarNO.Text = epc.Substring(4, 18);
        } 页面Form1下
 namespace R900APP_net
{
    public partial class Form1 : Form
    {
        /// <summary>
        /// main class
        /// </summary>
        public static UHFAPI_NET.UHFAPI_NET R900APP;public delegate void InventoryEPCDispacher(string epc);首先要经过Form1页面,然后打开PrivilegeInfo页面,当关闭PrivilegeInfo页面后,第二次打开PrivilegeInfo页面后,就出现了这个异常。
查了下网络:必须要重新实例化它才可以再引用,应该如何解决?

解决方案 »

  1.   

    public PrivilegeInfo()
    {
        Form1.R900APP.evtInventoryEPC += new UHFAPI_NET.UHFAPI_NET.InventoryEPCDispacher(ShowInventoryEPC);
        this.Disposed += delegate { Form1.R900APP.evtInventoryEPC -= ShowInventoryEPC; };  //<--
    }
    public void ShowInventoryEPC(string epc)
    {
        if (this.Disposing == false && this.IsDisposed == false)  //<--
        {
            this.txtEarNO.Text = epc.Substring(4, 18);
        }
    }
      

  2.   

    感谢gomoku
    指教,分全部奉上,能解释下原理吗,谢谢!
      

  3.   

    这个原理应该是,释放资源时没有将变量设置为null。