The following is a reference clip:
{
//
// CareEye
//
This. ServiceName = "CareEye ";
}
/**////
/// Clear all resources in use.
///
Protected override void Dispose (bool disposing)
{
If (disposing)
{
If (components! = Null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}
/**////
/// Set specific operations so that the service can perform its work.
///
Protected override void OnStart (string [] args)
{
// TODO: Add code here to start the service.
MainThread. Start ();
}
/**////
/// Stop the service.
///
Protected override void OnStop ()
{
// TODO: Add code here to stop the service.
MainThread. Abort ();
}
Public static void ThreadFunc ()
{
Int LastHour = DateTime. Now. Hour;
While (true)
{
System. Threading. Thread. Sleep (60000 );
If (DateTime. Now. Hour-1 = LastHour)
{
MessageBox. Show ("to take good care of your eyes, please take a 5-minute break and look into the distance! "," Warning ", MessageBoxButtons. OK, MessageBoxIcon. Warning, MessageBoxDefaultButton. Button1, MessageBoxOptions. defaulttoptoponly );
LastHour = DateTime. Now. Hour;
}
}
}
}
}
Add and install components:
On the Design page, right-click and select add installer from the shortcut menu. A new page is displayed, with the following controls: serviceProcessInstaller1 and serviceInstaller1.
Change the attribute Account to LocalSystem in serviceProcessInstaller1.
Change the attribute Parent to serviceProcessInstaller1 in serviceInstaller1. The ServiceName attribute is the name of the service after the service is generated.
After the token is completed, generate the token (fake name is w2.exe ). Find the generated EXE file in the corresponding folder, and find the two. EXE files with short names. Copy the file to the root directory of the drive F in a folder.
Install a service. Go to the cmd screen and enter the Framework2.0 file, for example:
Cd C: \ WINDOWS \ Microsoft. NET \ Frameworkv2.0.50727
After hitting
InstallUtil f: w2.exe. the uninstallation service is InstallUtil f: w2.exe-u.
Now you have to start the service,
Start the installed Service in windows.