日期:2014-05-18  浏览次数:20862 次

c# Invoke 在多线程中使用控件
c# Invoke 在多线程中使用控件 报出“未将对象初始化”bug
下列代码
delegate void BindDataDelegate(string tagId, int devId);


BindDataDelegate d = new BindDataDelegate(BindData);
d.Invoke(tagId,devId);

public void BindData(string tagid, int devid)
  {

  ConfigurationInfo coninfo = cons.GetConfigurationInfo();

  DateTime time = DateTime.Now;

  bsinfo = bsinfobll.GetProductInfo(tagid);

  if (lblPname.InvokeRequired)
  {
  lblPname.Text = bsinfo.Pname;

  }
}

就在在lblPname.Text = bsinfo.Pname; 这一行报错

------解决方案--------------------
应该是你的bsinfo等于null,判断一下,
------解决方案--------------------
支持楼上。bsinfo = bsinfobll.GetProductInfo(tagid);这一句是生成bsinfo的实例,当右边的方法没有取到值时,bsinfo对象就是null,即未实例化,所以在使用该对象时报“未将对象初始化”。