Search code examples
windows-servicesnotifyicon

Nofity User some message from a windows service


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.


Solution

  • There are several options such as these:

    1. Sockets: (Not too difficult to write, has firewall problems) You can find samples for it almost everywhere.
    2. 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.
    3. Named Pipes: (Probably the most difficult, but it's the recommended solution) Here is a Code Project sample.
    4. 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.