I have created a windows service which gets soem info from database and I want to notify user based on the info retreived from the DB. How can I notify user from a windows service using system tray notification? Can you please show me some sample (using IPC mechanism) to get the return value of a method used in a windows service in a system tray notification? Thanks in advance.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There are several options such as these:
- Sockets: (Not too difficult to write, has firewall problems) You can find samples for it almost everywhere.
- External WinForm: (The easiest method, has security problems and might blocked by some antivirus apps) Just create a winForm with the ability to go into the windows notification area and then tell the service to run its exe file.
- Named Pipes: (Probably the most difficult, but it's the recommended solution) Here is a Code Project sample.
- Other tricks like: Create a hidden winform project (ShowInTask=false) and put it in StartUp. provide it with a FileSystemWatcher object and make it watch for a certain file which the service creates or deletes it to signal the winform.