How can I show a Notification Area Balloon and Icon from a Windows Service?

后端 未结 3 1549
攒了一身酷
攒了一身酷 2021-01-03 00:49

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 t

相关标签:
3条回答
  • 2021-01-03 01:20

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

    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.

    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.

    Hope this helps.

    0 讨论(0)
  • 2021-01-03 01:24

    If you just want to send a simple command to your Windows service you can send it a message from your user app in the following way.

    ServiceController myService = new ServiceController("YOUR Service Name");
    myService.ExecuteCommand(123); // do something;
    

    If you override the OnCustomCommand method in you class the extends ServiceBase. You could then use this command to trigger the service to do somthing like reload a config file, or switch to some state.

    0 讨论(0)
  • 2021-01-03 01:30

    Our new (and free) ServiceTray utility will let you control your service from a tray icon. It will also show pop-up/balloon notifications when it detects that your service has changed state (started-> stopped, etc).

    0 讨论(0)
提交回复
热议问题