C# Windows Service - error 1053 the service did not respond to the start or control request?

From MSDN : Do not use the constructor to perform processing that should be in OnStart. Use OnStart to handle all initialization of your service. The constructor is called when the application's executable runs, not when the service runs.

The executable runs before OnStart. When you continue, for example, the constructor is not called again because the SCM already holds the object in memory. If OnStop releases resources allocated in the constructor rather than in OnStart, the needed resources would not be created again the second time the service is called If your timer is not initialized in the OnStart call, this could be a problem.

I would also check the type of timer, make sure its a System.Timers. Timer for Services Here is an example of how to setup the timer in a windows service.

From MSDN: "Do not use the constructor to perform processing that should be in OnStart. Use OnStart to handle all initialization of your service. The constructor is called when the application's executable runs, not when the service runs.

The executable runs before OnStart. When you continue, for example, the constructor is not called again because the SCM already holds the object in memory. If OnStop releases resources allocated in the constructor rather than in OnStart, the needed resources would not be created again the second time the service is called."

If your timer is not initialized in the OnStart call, this could be a problem. I would also check the type of timer, make sure its a System.Timers. Timer for Services.

Here is an example of how to setup the timer in a windows service. //TODONT: Use a Windows Service just to run a scheduled process I tried your code, and it seems ok. The only difference I had was to hard code the timer value (Service1.Cs).

Let me know if the below doesn't work. Service1.Cs using System; using System.Collections. Generic; using System.

ComponentModel; using System. Data; using System. Diagnostics; using System.

ServiceProcess; using System. Text; using System. Timers; using System.

Threading; namespace WindowsServiceTest { public partial class Service1 : ServiceBase { private System.Timers. Timer timer; public Service1() { InitializeComponent(); } protected override void OnStart(string args) { //instantiate timer Thread t = new Thread(new ThreadStart(this. InitTimer)); t.Start(); } protected override void OnStop() { timer.

Enabled = false; } private void InitTimer() { timer = new System.Timers.Timer(); //wire up the timer event timer. Elapsed += new ElapsedEventHandler(timer_Elapsed); //set timer interval //var timeInSeconds = Convert. ToInt32(ConfigurationManager.

AppSettings"TimerIntervalInSeconds"); double timeInSeconds = 3.0; timer. Interval = (timeInSeconds * 1000); // timer. Interval is in milliseconds, so times above by 1000 timer.

Enabled = true; } protected void timer_Elapsed(object sender, ElapsedEventArgs e) { int timer_fired = 0; } } } Service1.Designer.Cs namespace WindowsServiceTest { partial class Service1 { /// /// Required designer variable. /// private System.ComponentModel. IContainer components = null; /// /// Clean up any resources being used.

/// /// true if managed resources should be disposed; otherwise, false. Protected override void Dispose(bool disposing) { if (disposing && (components! = null)) { components.Dispose(); } base.

Dispose(disposing); } #region Component Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { components = new System.ComponentModel.Container(); this. ServiceName = "Service1"; this.

CanPauseAndContinue = true; } #endregion } } I just created a blank Windows Service project and add the below so I could run installutil. Exe and attach to the above to see if the event was firing (and it did). Using System; using System.Collections.

Generic; using System. Text; using System. ComponentModel; using System.

ServiceProcess; namespace WindowsServiceTest { RunInstaller(true) public class MyServiceInstaller : System.Configuration.Install. Installer { public MyServiceInstaller() { ServiceProcessInstaller process = new ServiceProcessInstaller(); process. Account = ServiceAccount.

LocalSystem; ServiceInstaller serviceAdmin = new ServiceInstaller(); serviceAdmin. StartType = ServiceStartMode. Manual; serviceAdmin.

ServiceName = "Service1"; serviceAdmin. DisplayName = "Service1 Display Name"; Installers. Add(process); Installers.

Add(serviceAdmin); } } }.

I just had the same problem. It turned out it was because I was running it as a console indebug mode - like the code you have above #if (!DEBUG) #else //debug code #endif And I had compiled it in debug mode and installed the service When I compiled it in release mode it worked as expected Hope this helps.

I go to the server console (in the server room) and start the service from there. Remote in wont' work.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions