I want to create windows service and for that i create the process and installer program also.
It installed well and I was ready to start my next move,but after starting the service it doesn't show anything.
I used this reference.
http://tech.pro/tutorial/895/creating-a-simple-windows-service-in-csharp
This is my program.cs file.
namespace WindowsService
{
class Program : ServiceBase
{
static void Main(string[] args)
{
ServiceBase.Run(new Program());
}
public Program()
{
this.ServiceName = "Battery Service";
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
Console.WriteLine("Hello World");
Console.ReadLine();
}
protected override void OnStop()
{
base.OnStop();
}
}
}
And next one is my installer file,WindowsServiceInstaller.cs
namespace WindowsService
{
[RunInstaller(true)]
public class WindowsServiceInstaller:Installer
{
public WindowsServiceInstaller()
{
var processInstaller = new ServiceProcessInstaller();
var serviceInstaller = new ServiceInstaller();
//set the privileges
processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller.DisplayName = "Battery Service";
serviceInstaller.StartType = ServiceStartMode.Manual;
//must be the same as what was set in Program's constructor
serviceInstaller.ServiceName = "Battery Service";
this.Installers.Add(processInstaller);
this.Installers.Add(serviceInstaller);
}
}
}
- Service is installed correctly as per the above reference link.
- Service appears in the Administrative Tools/Services and i started it.
- It also appears on the Task Manager. Though,not executing the code.
Help me.