I have solution which contain so many projects and windowservices. I modified coding on the application side of windowservice,after that i copied the exe regarding that service(F:\Components\Console\Bin\service.exe) in to the installation path(C:\Program Files\syscon\ Monitor\service.exe) after stopping windowservice from the 'services.msc'.Now i am getting the value on service while debugging which is not getting previously.But now when i start the service from 'services.msc' i am getting this error "Could not start the operational sentinel windows resource monitor service on local computer.Error 1053: The service did not respond to the start or control request in a timely fashion" Can any tell me a solution for this
Try debugging the Windows Service onstart event. Check this link, for debugging onStart event. Debugging Windows Services
We create many services during our work and one method for debugging I've found very useful is the following:
Make your service a "dual application" that can run as a service or as a normal Windows Forms application, controlled by some command line parameter. I pass "/gui" to my services.
In void Main(string[] args)
I check for the parameter:
If it is missing, I execute the code to instantiate the service (the code generated by Visual Studio).
If it is there, I run code to create a normal Windows Forms application, where the main form instantiates the service and calls OnStart
and OnStop
accordingly (you'll have to create wrapper methods due to visibility of OnStart
and OnStop
).
Of course you have to add the references to the Windows Forms assemblies manually and add code like Application.Run(...)
yourself, but debugging capabilities are greatly improved without going through the hassle of the "Stop Service, Copy File, Start Service, Fail"-routine.
Most likely, there's a bug in your OnStart
code which makes the instance drop out of that routine and the service manager keeps waiting.
EDIT
Here's a code sample for you of the way I create the service/gui depending on the parameter:
static void Main(string[] args)
{
if (args.Length > 0 && args[0].Equals("/gui"))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmGui());
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new SampleService() };
ServiceBase.Run(ServicesToRun);
}
}