我如何可以显示一个Windows服务通知区域气球和图标? [英] How can I show a Notification Area Balloon and Icon from a Windows Service?

查看:285
本文介绍了我如何可以显示一个Windows服务通知区域气球和图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有当用户启动他们的工作站一直运行Windows服务。此Windows服务是至关重要的,我想显示在通知区域气球通知当某些事情发生,如该服务停止,启动,重启等。

I have a Windows Service that is always running when the user starts their workstation. This Windows Service is critical and I would like to show a Balloon Notification in the Notification Area when certain things happen such as the Service Stops, Starts, Restarts etc.

例如:


For example:

此外,有没有一种方式来显示一个通知区域图标为我的Windows服务?

Also, is there a way to show a Notification Area Icon for my Windows Service?

推荐答案

Windows服务直接与桌面交互的时代已经结束了,所以你必须找到另一种方式。

The days of Windows services interacting directly with the desktop are over, so you have to find another way.

我所做的就是创建一个正常的WinForms应用程序,包括将NotifyIcon 。这个应用程序模拟任务管理器,例如,它可以从任务栏被隐藏,只在系统托盘中可见的行为。如果我右键点击系统托盘图标,我得到一个菜单。如果我双击该图标,显示应用程序窗口。

What I have done is create a normal WinForms application that includes a NotifyIcon. The behavior of this application mimics that of Task Manager, such that it can be hidden from the task bar and only visible in the system tray. If I right-click the system tray icon, I get a menu. If I double-click the icon, the application window is shown.

要方便WinForms应用程序和Windows服务之间的通信,我使用WCF。具体来说,我用的 Juval洛伊发布 - 订阅框架,该作品真的很好为这种情况的。看到这里我的回答 了解详细信息。

To facilitate the communication between the WinForms application and the Windows service, I use WCF. Specifically, I use Juval Lowy's Publish-Subscribe Framework, which works really well for this kind of scenario. See my answer here for more details.

希望这有助于。

这篇关于我如何可以显示一个Windows服务通知区域气球和图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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