当前窗体:MainForm
其中创建了两个线程:Thread1(执行工作线程)、Thread2(监控线程)。当Thread2发现Thread1执行完成并Abort后,Thread2执行关闭MainForm。我在Thread2中用如下代码关闭MainForm,但不起作用,请高手指点。
private delegate void CloseFormCallBack();
private void CloseForm()
{
if (this.InvokeRequired)
{
CloseFormCallBack CfB = new CloseFormCallBack(CloseForm);
this.Invoke(CfB);
}
else
{
this.Close();
this.Dispose();
}
}
其中创建了两个线程:Thread1(执行工作线程)、Thread2(监控线程)。当Thread2发现Thread1执行完成并Abort后,Thread2执行关闭MainForm。我在Thread2中用如下代码关闭MainForm,但不起作用,请高手指点。
private delegate void CloseFormCallBack();
private void CloseForm()
{
if (this.InvokeRequired)
{
CloseFormCallBack CfB = new CloseFormCallBack(CloseForm);
this.Invoke(CfB);
}
else
{
this.Close();
this.Dispose();
}
}
解决方案 »
- C# winform程序,怎样加载图标??
- 尝试读取或写入受保护的内存。这通常指示其他内存已损坏
- (50分)C#如何实现本地的两个程序间的通讯?
- 一个表,两个字段,要显示表中的两列数据.如果一条数据中一个字段没有,就用另一个字段对应的数据.有的话就用自己的.怎么弄,急等!!!!
- SqlDataReader对像的什么方法可以通过字段段获取值
- 哪里有存储过程的教材吗,分不多但马上结分!
- 关于给线程传递参数的问题
- 求助,已经发布到IIS上的网站,水晶报表导出word时,所有使用网站的全部自动刷新到登陆页面
- C#查询
- IIS ARR URLREWRITE 设置后,不能跨域redirect
- 请问如何捕获打印任务的错误信息,并跳过当前出错任务执行打印机队列中的下一个任务?
- AJAX出现的问题?
-------------------------------------
应该让MainForm去监视Thread1,当Thread1完成后,MainForm先关掉Thread2线程,再关闭自己
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ParameterizedThreadStart(dothing));
t.Start();
}
void closefrm()
{
this.Close();
} void dothing(object s)
{
if (this.InvokeRequired)
{
closefrmCallBack cb = new closefrmCallBack(closefrm);
this.Invoke(cb);
}
else
{
this.closefrm();
}
}