当我尝试从 backgroundworker_RunWorkerCompleted 事件打开时,Winform 未显示?
我的操作的细节是我有一个 winform,其中仅包含进度条,我做了一些计算并将最终值存储在数据库中。为此,我使用了进度条和后台工作线程。 我正在后台工作线程事件 doWork 事件中进行所有计算。 当backgroundworker完成时,它调用RunWorkerCompleted事件,我试图在其中打开另一个winform。 问题是 winform 不可见。
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (!string.IsNullOrEmpty(click)) {
if (click == "sales") {
Sales sales = new Sales();
sales.MdiParent = mdiStockApp.mdi;
sales.Show();
sales.Activate();
}
}
}
这是 RunWorkerCompleted 事件,我试图在其中打开另一个事件。刚才我也尝试了 form.Activate() 但仍然没有
the detail of my action is i have a winform which contains only progress bar which i made to do some calculations and stored the final value in db.for this i used progress bar and backgroundworker thread.
i am doing all calculation in backgroundworker thread event doWork event.
When backgroundworker is finish it calls RunWorkerCompleted event, in which i am trying to open another winform.
The problem is that winform doesnt get visible.
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (!string.IsNullOrEmpty(click)) {
if (click == "sales") {
Sales sales = new Sales();
sales.MdiParent = mdiStockApp.mdi;
sales.Show();
sales.Activate();
}
}
}
this is the RunWorkerCompleted event in which i am trying to open another event. just now i tried with form.Activate() too but still no
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是BackgroundWorker OnWorkCompleted抛出跨线程异常?在另一个线程中尝试 UI 处理,检查 this.IsInvokeRequired 属性并使用 this.Invoke(...)
It may be that BackgroundWorker OnWorkCompleted throws cross-thread exception ? Try UI handling in another thread, check this.IsInvokeRequired property and use this.Invoke(...)