如何继续调用的ShowDialog后执行代码() [英] How to continue executing code after calling ShowDialog()

查看:1934
本文介绍了如何继续调用的ShowDialog后执行代码()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Form.ShowDialog()方法会导致停止代码,直到新形式被称为封闭。我需要的代码的ShowDialog()方法被调用后继续运行。我用Google搜索和阅读有关使用BackgroundWorker的? 。但是,这是我第一次听说过这一点,以前从来没有使用过

the Form.ShowDialog() method causes the code to be halted until the newly called form is closed. I need the code to continue running after the ShowDialog() method is called. I googled and read about using backgroundworker? But that is the first time i have heard of that and never used it before.

Form2 form2this = new Form2();
form2this.ShowDialog();
MessageBox.Show("Something");

这代码被点击一个按钮后执行的,我怎么能还叫ShowDialog的,以防止用户交互与主要形式,但仍允许的主要形式继续其工作的?

This code gets executed after clicking a button, how can i still call ShowDialog to prevent the user from interacting with the main form but still allowing the main form to continue with its work?

很抱歉,如果它被讨论,但一切我发现,似乎极难执行这样一个简单的任务。我其实感到惊讶它不包括在ShowDialog方法。例如ShowDialog的()。继续会很酷。

Sorry if its been discussed but everything i found seems extremely difficult to perform such a simple task. I am actually surprised its not included in the SHowDialog method. for instance ShowDialog().Continue would be cool.

推荐答案


  • 如果你只是想代码以继续而不是阻塞,直到弹出窗口关闭考虑使用显示而不是的ShowDialog

如果您有想要有父窗体做,而子窗体是一些动作,那么是的,它可能是适当用一个BackgroundWorker(或只是手动开始一个新的线程/任务)。这将有助于进一步了解该任务是什么,但。如果你需要使用的主要形式,或子窗体交互,那么这似乎是麻烦我。如果您只是需要做一些后台任务,没有用户界面交互,那么这是思想的行权。

If you have some action that you want to have the parent form doing while the child form is up, then yes, it could be appropriate to use a BackgroundWorker (or just manually starting a new Thread/Task). It would be helpful to know more about what that task is though. If you need to interact with the main form, or the child form, then that seems like trouble to me; if you just need to do some background task with no UI interaction then this is the right line of thought.

另一种可能是你想要做什么真正只是应该是在孩子的形式完成,而不是父窗体。

Another possibility is that what you want to do really just should be something done in the child form, rather than the parent form.

这篇关于如何继续调用的ShowDialog后执行代码()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆