如何使用Windows服务打开Winform [英] How to open a winform using windows service

查看:542
本文介绍了如何使用Windows服务打开Winform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮帮我.我是.NET的新手.任何人都知道如何使用Windows服务打开Winform.请帮帮我.在此先谢谢您.

Please Help me out. I am new in .NET. Anybody know how to open a winform using windows service.Pleas help me. Thanks in advance.

推荐答案

您不能.但是,您可以使用一种可以与系统上运行的服务进行交互的形式.
You cannot. You can however, have a form that can interact with services that are running on the system.


服务是长期运行的可执行文件,不需要用户干预. 请参阅此处以获取更多信息 [ ^ ].
因此,无法从服务中打开表单.即使有可能,也不建议这样做.也许您想制作一个与服务进行通信的应用程序?如果是这种情况, Windows Communication Foundation [ ^ ]可能就是您所需要的需要.
或者,也许您需要重新考虑自己的策略,并问自己是否真的需要服务:)
A service is a long running executable that does not require user intervention. See here for more information[^].
As such it is not possible to open a Form from a service. And even if it is possible it is not recommended. Perhaps you want to make an application that communicates with a service? If that is the case Windows Communication Foundation[^] may be what you need.
Or maybe you need to rethink your strategy and ask yourself if you REALLY need a service :)


要合乎逻辑:即使没有人登录,Windows Service也会继续运行.您想在哪里显示表格?您可能对服务的概念感到困惑.但是,拥有一个可以与服务交互的单独的窗口化进程并没有错.请参阅Abhinav和Naerling的解决方案.

此外,这是一种非常典型的方法,尤其是用于服务控制.

顺便说一句,此类应用程序最合适的形式是基于System.Windows.Forms.NotifyIcon类的 System Tray应用程序.请参阅 http://msdn.microsoft.com/en-us/library/system .windows.forms.notifyicon.aspx [ ^ ].

—SA
Be logical: a Windows Service keeps running even if nobody logged on. Where do you want to show a form? You are probably confused about the very concept of the service. However, there is nothing wrong in having a separate Windowed process which can interact with the Service. See the solutions by Abhinav and Naerling.

Moreover, this is a very typical approach used, in particular, for Service control.

By the way, the most adequate form of such application is the System Tray application based on the class System.Windows.Forms.NotifyIcon. See http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx[^].

—SA


这篇关于如何使用Windows服务打开Winform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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