Use a tray to control the c # implementation of windows services
Source: Internet
Author: User
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;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.