C#中多线程里面如何调用控件
1个回答
2018-08-17 · 知道合伙人互联网行家
关注
展开全部
定义委托,然后用invoke
private void ucMidPartsid_Load(object sender, EventArgs e)
{
if (is_Load == true)
{
thread = new Thread(new ThreadStart(this.LoadData));
thread.Start();
}
//if (datafinish != null)
//{
// datafinish(this, e);
//}
}
private void LoadData()
{
QueryDataCallBack deleg;
deleg = new QueryDataCallBack(this.DataBinding);
this.Invoke(deleg,null);
}
private void DataBinding()
{
partstableAdapter = new GreatWall.SCM.Parts.DataAccess.DAParts.PartsTableAdapter();
partstableAdapter.Fill(dsParts.GB_PARTS);
cobMidPartsid.DataSource = dsParts.GB_PARTS;
cobMidPartsid.DisplayMember = "B_PARTSID";
cobMidPartsid.ValueMember = "B_ID";
EventArgs e = new EventArgs();
if (datafinish != null)
{
finish = true;
datafinish(this, e);
}
}
private void ucMidPartsid_Load(object sender, EventArgs e)
{
if (is_Load == true)
{
thread = new Thread(new ThreadStart(this.LoadData));
thread.Start();
}
//if (datafinish != null)
//{
// datafinish(this, e);
//}
}
private void LoadData()
{
QueryDataCallBack deleg;
deleg = new QueryDataCallBack(this.DataBinding);
this.Invoke(deleg,null);
}
private void DataBinding()
{
partstableAdapter = new GreatWall.SCM.Parts.DataAccess.DAParts.PartsTableAdapter();
partstableAdapter.Fill(dsParts.GB_PARTS);
cobMidPartsid.DataSource = dsParts.GB_PARTS;
cobMidPartsid.DisplayMember = "B_PARTSID";
cobMidPartsid.ValueMember = "B_ID";
EventArgs e = new EventArgs();
if (datafinish != null)
{
finish = true;
datafinish(this, e);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询