简体   繁体   English

在Windows Service C#中显示消息框和Windows窗体

[英]Display Message box and windows form in Windows Service c#

I need to display Message Box and Windows Forms through windows service by using c#. 我需要使用c#通过Windows服务显示消息框和Windows窗体。 Anyone Please help me. 有人请帮助我。 Thanks in advance. 提前致谢。

You cannot (easily) do this directly from the service's process. 您不能(轻松)直接从服务过程中执行此操作。 As descibed here , there is a way to create an interactive service, that is able to send/process windows messages and display windows. 如此处所述 ,有一种创建交互式服务的方法,该方法能够发送/处理Windows消息和显示窗口。

But : Since Windows Vista, all services run in a separate user session, named "session 0". 但是 :从Windows Vista开始,所有服务都在单独的用户会话(称为“会话0”)中运行。 Thus, all windows displayed by services, are displayed in that session. 因此,服务显示的所有窗口都显示在该会话中。 It is theoretically possible (I have even done that once, just for fun), to switch to this session and view these windows, but this would hardly be of use in real life. 从理论上讲,有可能(为了娱乐,我什至做过一次)切换到该会话并查看这些窗口,但这在现实生活中几乎没有用。

My advice would be to create a separate gui application (maybe one with a nice tray icon), that communicates with your service via eg TCP/IP or a database. 我的建议是创建一个单独的gui应用程序(可能带有一个精美的托盘图标),该应用程序通过例如TCP / IP或数据库与您的服务进行通信。 This application can then handle any required user interaction and do the appropriate interaction with the service's process. 然后,该应用程序可以处理任何所需的用户交互,并与服务流程进行适当的交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM