使用另一个线程上的方法/函数打开另一个表单?
当方法/或函数打开第二个表单时,是否可以打开我的第二个表单 在另一个线程上?
我读过与此相关的其他主题.. 但似乎我不知道如何使用调用
这是我打开第二个表单的方法 当我打电话时..什么也没有发生..(因为它在第二个线程上)
TimerMode f2 = new TimerMode();
f2.ShowDialog();
请帮助我。我是多线程新手..
is it possible to open my second form, when the method/or function opening the 2nd form
is on another thread?
i have read other threads related to this..
but it seems i cant figure out how to use the invoke
here's how i open the 2nd form
when im calling this.. nothing just happens..(because its on the 2nd thread)
TimerMode f2 = new TimerMode();
f2.ShowDialog();
please help me. i newbie to multi -threading..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在主窗口线程上执行
尝试以下操作:
这将在正确的线程上创建它。
You need to execute on the main window thread
Try the following:
This will create it on the right thread.
它应该做点什么。这是因为
ShowDialog
将运行自己的消息循环。TimerMode
表单至少应该是可见且有效的。但是,您是对的,这确实不是最佳实践,特别是如果此表单将与已在主 UI 线程上运行的其他表单进行交互。您可以按照以下方法进行操作。
请注意,
anotherForm
是对已托管在主 UI 线程上的其他表单之一的引用。It should be doing something. That is because
ShowDialog
will run its own message loop. TheTimerMode
form should at least be visible and functioning. But, you are right, this really is not the best practice especially if this form will be interacting with the other forms which are already running on the main UI thread.Here is how you might do it.
Note that
anotherForm
is a reference to one of your other forms which is already hosted on the main UI thread.