winform问题,在backgroundwork里使用委托在委托里又用到了委托,结果我的进度条无法显示

l2Hyacinth 2016-06-03 05:59:37
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);
}
}
我的疑问就是为什么在线程里委托包含使用委托会影响到我的进度条???希望各位大哥大姐能指点指点
...全文
647 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
l2Hyacinth 2016-06-16
  • 打赏
  • 举报
回复
在线程里绑定数字要操作DGV不放里面会报错,这样写有什么问题吗?
exception92 2016-06-13
  • 打赏
  • 举报
回复
this.Invokeke(new MethodInvoker(delegate { BindGridUp(ds1, ds2); })); 这会对?

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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