winform问题,在backgroundwork里使用委托在委托里又用到了委托,结果我的进度条无法显示
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
try
{
//外层的委托
this.Invoke(new MethodInvoker(delegate
{
//判断选中的tab页
if (this.tabControl1.SelectedTab.Name == "tabPage1")
{
//内层的委托
new MethodInvoker(delegate
{
BindGridUp(ds1, ds2);
}));
}
if (this.tabControl1.SelectedTab.Name == "tabPage2")
{
this.Invoke(new MethodInvoker(delegate
{
BindGridRight(ds3);
}));
}
}));
}
catch(Exception ex)
{
DataClass.UserFunc.WriteLog("压包错误!" + ex.Message);
MessageBox.Show("报错:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
以上的代码会影响我的进度条不显示,下面是我修改后的代码,没有在委托里继续使用委托
//查询数据
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
try
{
//外层委托不使用
//this.Invoke(new MethodInvoker(delegate
//{
//间接的判断是哪个tab页被选中
if (tabPage11==true)
{
this.Invokeke(new MethodInvoker(delegate
{
BindGridUp(ds1, ds2);
}));
}
if (tabPage22==true)
{
this.Invoke(new MethodInvoker(delegate
{
BindGridRight(ds3);
}));
}
//}));
}
catch(Exception ex)
{
DataClass.UserFunc.WriteLog("压包错误!" + ex.Message);
MessageBox.Show("报错:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
我的疑问就是为什么在线程里委托包含使用委托会影响到我的进度条???希望各位大哥大姐能指点指点