无法从回调中显示Winform [英] can't display winform from callback

查看:114
本文介绍了无法从回调中显示Winform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Windows应用程序项目,当您运行该应用程序时,它并没有立即显示一个窗体,而是运行了Application.Run在ApplicationContext上运行,该应用程序将WCF服务连接到WCF服务器,该服务器可以在我创建的Windows应用程序上调用方法,因为我使用的是双工连接,当服务器在服务使用者上调用方法时,它会以表格形式传递Application.Run(new Form1),这是第一次WCF服务器做到这一点,它工作正常,但第二次不显示该表单,有人可以告诉我为什么会这样吗,因为我已经调用了Application.Run已经运行一次了吗?

Hi I''ve created a windows application project, when you run the application it doesn''t show a form straight away i run Application.Run on a ApplicationContext which makes a WCF service connection to a WCF server, the server can call methods on the windows application i''ve created because i''m using a duplex connection, when the server calls a method on the service consumer it does Application.Run(new Form1) passing in a form, the first time the wcf server does it, it works fine but the second time the form doesn''t show, can anyone tell me why this is happening is it because i''ve already called Application.Run once already ?

推荐答案

来自MSDN:
此方法将事件处理程序添加到Closed事件的mainForm参数中.事件处理程序调用ExitThread清理应用程序"

参见链接:
http://msdn.microsoft.com/en-us/library/ms157902.aspx [ ^ ]

因此,您不能再调用它一次.
From MSDN:
"This method adds an event handler to the mainForm parameter for the Closed event. The event handler calls ExitThread to clean up the application"

See the link:
http://msdn.microsoft.com/en-us/library/ms157902.aspx[^]

So you can''t call it more that once.


为什么您不能运行最初隐藏的表单,然后在出现时显示它(或其他合适的表单)您准备好了吗?
Why can''t you run a form that''s initially hidden, and then show it (or another appropriate form) when you''re ready?


调用无参数版本的Application.Run ,因此您的消息循环已启动并正在运行.现在,在WCF回调处理程序中,显示一个新表单.不过,您将必须手动处理应用程序终止.
Call the parameter-less version of Application.Run so your message loop is up and running. Now in your WCF callback handler, show a new form. You will have to manually handle application termination though.


这篇关于无法从回调中显示Winform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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