${res:Templates.Project.WindowsService.Name}
C#
C#.Project.ServiceProject
C#
${res:Templates.Project.WindowsService.Description}
${ProjectName}
/// This is the class for my Service
///
public class MyService : System.ServiceProcess.ServiceBase
{
public MyService()
{
InitializeComponents();
// TODO: Add any further initialization code
}
private void InitializeComponents()
{
this.ServiceName = "MyService";
}
///
/// This method starts the service.
///
public static void Main()
{
System.ServiceProcess.ServiceBase.Run(new System.ServiceProcess.ServiceBase[] {
new MyService() // To run more than one service you have to add them here
});
}
///
/// Clean up any resources being used.
///
protected override void Dispose(bool disposing)
{
// TODO: Add cleanup code here (if required)
base.Dispose(disposing);
}
///
/// Start this service.
///
protected override void OnStart(string[] args)
{
// TODO: Add start code here (if required)
// to start your service.
}
///
/// Stop this service.
///
protected override void OnStop()
{
// TODO: Add tear-down code here (if required)
// to stop your service.
}
}
}
[RunInstaller(true)]
public class ProjectInstaller : Installer
{
public ProjectInstaller()
{
ServiceProcessInstaller spi = new ServiceProcessInstaller();
spi.Account = ServiceAccount.LocalSystem;
ServiceInstaller si = new ServiceInstaller();
si.ServiceName = "Hello Service Template";
si.StartType = ServiceStartMode.Automatic;
Installers.AddRange(new Installer[] {spi, si});
}
}
]]>