For last few days I was not able to start a .Net Windows Service that I created. It gets installed properly and when start it from Services window, I pops up a message saying:
“ MyTestinSvc service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service."
Well, after lot of trial and error I found these are the main reasons for such an error:
1.You need to have a serviceController in you class:
private System.ServiceProcess.ServiceController serviceController1;
2. You need to have a Main method
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new ApproStubSvc1() };
ServiceBase.Run(ServicesToRun);
}
3. You must have InitializeCopmponent methd
private void InitializeComponent()
{
this.serviceController1 = new System.ServiceProcess.ServiceController();
this.serviceController1.ServiceName = "MyTestSvc";
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.ServiceName = " MyTestSvc ";
}
4. You must call InitializeComponent method in the class constructor
public ApproStubSvc1()
{
InitializeComponent();
}
It should solve the problem.
Subscribe to:
Post Comments (Atom)
1 comment:
This bug - "Some services stop automatically if they have no work to do" also happens for BizTalk Server.
Its difficult to find out why it came up. The event log message can be confusing. But the event log message gives you the clue to the cause. The other day I faced this bug and event log was telling something Database SQL connection failed..etc. The finally I found out that the BizTalk Config file has some custom config settings which was causing this. The bug was, the developer put some DB connection stuff in in <AppSettings> section, but he did it in a second <AppSettings> section. Well, you can not have 2 such section in the config file.
This solved the problem and BizTalk service started normally.
Post a Comment