当我致电Windows服务时,为什么NotifyIcon无法显示在系统托盘中? [英] NotifyIcon not show in sys tray when i call windows service why?

查看:106
本文介绍了当我致电Windows服务时,为什么NotifyIcon无法显示在系统托盘中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在Windows应用程序的设计器中创建一个NotifyIcon并为其分配图标,则它可以正常工作.它显示在托盘中,并且表现正常.
但是,如果我在Windows服务中创建它,则安装该服务并运行它-图标不会显示在托盘中.我不知道为什么.
有什么建议吗?

删除了常规文本的代码块. [\ Edit]

If I create a NotifyIcon in a designer of a windows application and assign an icon to it - it works just fine. It shows up in the tray, and behaves just as it should.
However, if I create it in a windows service, then install that service and run it - the icon doesn''t show up in the tray. I have no idea why.
Any suggestions?

Code Block Removed for normal text. [\Edit]

推荐答案

不要将图标放入服务中.由于即使用户注销,该服务仍将运行,因此没有一个看不见的图标是没有意义的.

将您的应用分为两部分.处理实际工作的服务,以及在用户登录时运行的UI组件.此UI应用程序与该服务对话,并向其提供来自用户的任何命令.它还可以告诉用户应用程序需要什么来更新托盘中图标的显示.
Don''t put the icon in the service. Since the service will still be running even when the user logs off, there is no point in having an icon that can''t be seen.

Split your app into two parts. The service that handles the actual work and a UI component that is run when a use logs in. This UI application talks to the service and supplies any commands to it that come from the user. It can also tell the user application anything it needs to to update the display of the icon in the tray.


请选中此 ^ ]


这篇关于当我致电Windows服务时,为什么NotifyIcon无法显示在系统托盘中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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