简体   繁体   English

C# 向用户显示 Windows 服务更新通知

[英]C# Show windows service updates notification to user

I am new to .NET and seeking help for the Windows Service Updates Notifications.我是 .NET 新手,正在寻求有关 Windows 服务更新通知的帮助。

I have a use case that is somewhat similar to "https://stackoverflow.com/questions/41232170/c-sharp-show-notification-prompting-a-update".我有一个类似于“https://stackoverflow.com/questions/41232170/c-sharp-show-notification-prompting-a-update”的用例。

The application is developed in C#.NET and is deployed and running as Windows Service.该应用程序使用 C#.NET 开发,并作为 Windows 服务部署和运行。 However, the application is not using any MSI installer to install it.但是,该应用程序没有使用任何 MSI 安装程序来安装它。 I am using a batch script that configures the Windows Service application.我正在使用配置 Windows 服务应用程序的批处理脚本。

Now, I want to show the notifications about the updates about the Windows Service to the user, when the system gets restarted.现在,我想在系统重新启动时向用户显示有关 Windows 服务更新的通知。

I came across about the usage of WCF or by using the Task Scheduler, but not sure which one would be the better solution.我遇到了 WCF 的使用或通过使用任务计划程序,但不确定哪一个是更好的解决方案。

Please advice.请指教。

Ok, there are (were, because MS disabled the first one that I'm going to explain) two ways to notify your user about updates from a service.好的,有(因为 MS 禁用了我将要解释的第一个)有两种方法可以通知您的用户有关服务更新的信息。

First, the bad, ugly (and non-working in recent versions) way: interactive services.首先,糟糕的、丑陋的(并且在最近的版本中不起作用)方式:交互式服务。

You can configure a service as interactive , if you add the SERVICE_INTERACTIVE_PROCESS flag the service will be able to create a GUI that will be attached to Display_0.您可以将服务配置为 Interactive ,如果您添加 SERVICE_INTERACTIVE_PROCESS 标志,该服务将能够创建将附加到 Display_0 的 GUI。 This presents a ton of problems (trying to show a GUI when there's no user session, if you have two sessions open only the first one will show the GUI and so on) but it's a cheap dirty way to show data to the user.这就提出了一个吨的问题(试图表明一个GUI时,有没有用户会话,如果有两个会话打开只有第一个将显示GUI等),但它是一种廉价的肮脏的方式来显示数据给用户。 Avoid it.躲开它。

Second, the right way: a standalone GUI program.第二,正确的方法:一个独立的 GUI 程序。

In this case you create a secondary program that will show the data to the user, you can start it with the user session or let the user decide if he wants to receive info by opening manually this application.在这种情况下,您创建了一个辅助程序来向用户显示数据,您可以通过用户会话启动它,或者让用户通过手动打开此应用程序来决定他是否要接收信息。 This program needs to receive the updates from the service in some way, which is better is up to you but I would use UDP for this, in this way your service doesn't needs to care if any GUI app is connected or not, you broadcast an UDP message and everyone listening will receive it, you don't need to mantain a server that handles connections, you don't need to have an storage in order to maintain the event data and it will support any number of instances of the GUI (if more than one user has started a session in the machine all of them will get notified).该程序需要以某种方式从服务接收更新,这取决于您,但我会为此使用 UDP,这样您的服务就不需要关心是否连接了任何 GUI 应用程序,您广播一个 UDP 消息,每个监听的人都会收到它,你不需要维护一个处理连接的服务器,你不需要为了维护事件数据而有一个存储,它将支持任意数量的实例GUI(如果有多个用户在机器中启动了一个会话,所有用户都会收到通知)。

But as I said, that would be my preference, you can do it as fancy as you want, you can use Pipes, use a file that contains the event and use a FileSystemWatcher to get notified when changes happen in it, you can even host an ASP .net web app which implements a SignalR hub and then you can create your GUI in html.但是正如我所说,这将是我的偏好,您可以随心所欲地进行操作,您可以使用管道,使用包含事件的文件并使用 FileSystemWatcher 在其中发生更改时获得通知,您甚至可以托管一个实现 SignalR 集线器的 ASP .net Web 应用程序,然后您可以在 html 中创建您的 GUI。 It's up to you decide which mechanism is the best for your scenario.由您决定哪种机制最适合您的方案。

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

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