首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c# Invoke 在多线程中使用控件解决方案

2012-03-23 
c# Invoke 在多线程中使用控件c# Invoke 在多线程中使用控件报出“未将对象初始化”bug下列代码delegate voi

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,即未实例化,所以在使用该对象时报“未将对象初始化”。


热点排行