objectdisposedexception was unhandled 异常

心灵彩虹 2011-08-23 08:03:21
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页面后,就出现了这个异常。
查了下网络:必须要重新实例化它才可以再引用,应该如何解决?
...全文
160 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
心灵彩虹 2011-08-23
  • 打赏
  • 举报
回复
这个原理应该是,释放资源时没有将变量设置为null。
心灵彩虹 2011-08-23
  • 打赏
  • 举报
回复
当然解决了[Quote=引用 4 楼 wuzhanhui 的回复:]
引用 1 楼 gomoku 的回复:
C# code
public PrivilegeInfo()
{
Form1.R900APP.evtInventoryEPC += new UHFAPI_NET.UHFAPI_NET.InventoryEPCDispacher(ShowInventoryEPC);
this.Disposed += delegate { Form1.R900APP.e……
[/Quote]
心灵彩虹 2011-08-23
  • 打赏
  • 举报
回复
感谢gomoku
指教,分全部奉上,能解释下原理吗,谢谢![Quote=引用 1 楼 gomoku 的回复:]
C# code

public PrivilegeInfo()
{
Form1.R900APP.evtInventoryEPC += new UHFAPI_NET.UHFAPI_NET.InventoryEPCDispacher(ShowInventoryEPC);
this.Disposed += delegate { Form1.R900APP.evtInventor……
[/Quote]
freemangood 2011-08-23
  • 打赏
  • 举报
回复
楼主,出现了什么异常啊,没看懂异常描述在哪!?……
gomoku 2011-08-23
  • 打赏
  • 举报
回复
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);
}
}

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧