ProcessBox在ui线程打开也要在ui线程关闭 public void ThreadControl() {
this.BeginInvoke(new EventHandler(delegate
{
ProcessBox.getProcessBox().Close();
}));
}
this.BeginInvoke(new EventHandler(delegate
{
ProcessBox.getProcessBox().Close();
}));
}
{
ProcessBox.getProcessBox().Close();
}));
是又开启一个线程??那现在不是有3个线程了?
所以我的....数据查询过程代码....才是应该用Thread th=new Thread(数据查询函数) 这种方式来开启线程是吗?
到底是Thread th=new Thread(thread_fun)这种方式开启线程
还是用BeginInvoke这种方式开启线程啊
还是用委托的BeginInvoke方法来开启线程啊?
我就是想实现等待数据查询的时候,会有那种ProcessBox让人看见,以免让用户因为数据还没有查询出来,而以为界面卡死了
我就是想实现等待数据查询的时候,会有那种ProcessBox让人看见,以免让用户因为数据还没有查询出来,而以为界面卡死了我明白你的需求,你加一个控件到datagridview里用于显示等待信息,需要的时候让它出来,不需要时就隐藏和删除它,很简单的
“关闭主窗体中用ShowDialog打开的子窗体”这个问题解决了
我在研究“那delegate的Invoke和BeginInvoke 和Thread th=new Thread(thread_fun)都是用来开启线程的吧”这个问题
{
CrossThreadControl hander = new CrossThreadControl(ThreadControl);
hander.BeginInvoke(new AsyncCallback(writeComplete), null);
ProcessBox.getProcessBox().ShowDialog();
} private void writeComplete(IAsyncResult reslut)
{
CrossThreadControl handler = (CrossThreadControl)((AsyncResult)reslut).AsyncDelegate;
handler.EndInvoke(reslut);
} public void ThreadControl()
{
this.Invoke(new CrossThreadControl(delegate
{
ProcessBox.getProcessBox().SetText("aaaa");
}));
int num = 0;
for (int n = 0; n < 100000; n++)
{
for (int m = 0; m < 10000; m++)
{
num++;
}
}
this.Invoke(new CrossThreadControl(delegate
{
ProcessBox.getProcessBox().Close();
}));
}用你说的方法果断好了,马上给分