The vb Code provided by Chapter e of Mencius is now translated from this code into c # for reference by people who are used to c #.
Note that the image must be in ico format. Otherwise, the tray may not be displayed.
Using System;
Namespace UBISerialsController
{
/// <Summary>
/// Summary of Class1.
/// </Summary>
Public class Class1
{
Static System. ServiceProcess. ServiceController SC;
Static System. Windows. Forms. policyicon ni;
Static System. Windows. Forms. ContextMenu cm;
Static System. Timers. Timer timer;
Public Class1 ()
{
//
// TODO: add the constructor logic here
//
}
Static void Main ()
{
Try
{
SC = new System. ServiceProcess. ServiceController ("UBISerials ");
Ni = new System. Windows. Forms. policyicon ();
Ni. Visible = false;
Cm = new System. Windows. Forms. ContextMenu ();
Cm. MenuItems. Add (new System. Windows. Forms. MenuItem ("stop", new EventHandler (StopService )));
Cm. MenuItems. Add (new System. Windows. Forms. MenuItem ("Suspend", new EventHandler (PauseService )));
Cm. MenuItems. Add (new System. Windows. Forms. MenuItem ("continue", new EventHandler (ContiuneService )));
Cm. MenuItems. Add (new System. Windows. Forms. MenuItem ("START", new EventHandler (StartService )));
Cm. MenuItems. Add ("-");
Cm. MenuItems. Add (new System. Windows. Forms. MenuItem ("About", new EventHandler (About )));
Cm. MenuItems. Add (new System. Windows. Forms. MenuItem ("Exit", new EventHandler (Exit )));
Ni. ContextMenu = cm;