1

I have created a windows service in C#. I want this service to be moved to the system tray and have a popup menu with start/stop options and a settings form should also open from the menu.

Can anyone please guide me.

ase
  • 13,231
  • 4
  • 34
  • 46
meriaz
  • 65
  • 1
  • 11
  • Probably this can help you https://www.simple-talk.com/dotnet/.net-framework/creating-tray-applications-in-.net-a-practical-guide/ – Ajay Bhasy Aug 04 '15 at 10:01

1 Answers1

0

I also wanted to do this once, you can do it by adding a NotifyIcon to the service. Then adding this to the script

notifyIcon1.MouseClick += notifyIcon1_MouseClick;

void notifyIcon1_MouseClick(object sender, MouseEventArgs e) {
//yourcodehere
}

Then add a ServiceController class to handle stopping and starting the service

you can also add the following to handle the workstation being locked

Microsoft.Win32.SystemEvents.SessionSwitch += 
new Microsoft.Win32.SessionSwitchEventHandler(SystemEvents_SessionSwitch);
void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.SessionSwitchEventArgs e) {
            //yourcodehere
      }
Darkestlyrics
  • 310
  • 1
  • 5
  • 16