0

I try to create a windows service which automatically startsup. I am able to install and deinstall the service. If I try to start it, I get following error message: "Der Dienst antwortete nicht rechtzeitig auf die Start- oder Steueranfrage". (I try to translate) "The service don't respont in time on start or control request".

Here is my poor code

 public class LisaServerService: System.ServiceProcess.ServiceBase { private Program lisaServerServiceProgram; public static string LisaServiceName = "LISA-ServerService"; [STAThread] public static void Main(string[] args) { LisaServerService lisaServerService = new LisaServerService(); if (Environment.UserInteractive) { lisaServerService.OnStart(args); Console.WriteLine("I am a service. Normally you can't see the console... just ignore me"); Console.ReadLine(); lisaServerService.OnStop(); } else { ServiceBase.Run(lisaServerService); } } public LisaServerService() { InitializeComponent(); } private void InitializeComponent() { this.CanShutdown = true; this.ServiceName = "LISA - ServerService"; this.CanPauseAndContinue = true; this.lisaServerServiceProgram = new Program(); } protected override void OnStart(string[] args) { lisaServerServiceProgram.Start(null); base.OnStart(args); } protected override void OnStop() { lisaServerServiceProgram.Stop(); base.OnStop(); } protected override void OnShutdown() { OnStop(); base.OnShutdown(); } } 

Program.cs

 public class Program { public Program() { Logger.LogLevel = LogLevel.Information; Logger.LogRange = LogRange.Write; Logger.Log("Logger initialized"); } public void Start(string[] args) { DatabaseHandler.StartDatabase(); NetworkHandler.StartNetwork(); Logger.Log("Service started"); } 

if I run the service as a console program, it works fine. So the db connection + logger are working fine too. (Also within < 10ms)

8
  • What do the constructors of Program and LisaServerService look like? Commented Sep 4, 2013 at 20:18
  • I'd say that your OnStart method never returns.. Does it? Commented Sep 4, 2013 at 20:18
  • Any hint on the event viewer? Commented Sep 4, 2013 at 20:19
  • Maybe the credentials running the service are insufficient for access to the database? Also I get the feeling it would be best practice to separate the service itself from the main function. Commented Sep 4, 2013 at 20:38
  • Have you tried setting a breakpoint and see if it throws an exception somewhere? Commented Sep 4, 2013 at 20:40

1 Answer 1

1

If you're running the service in interactive mode it's waiting for the console here:

if (Environment.UserInteractive) { lisaServerService.OnStart(args); Console.WriteLine("I am a service. Normally you can't see the console... just ignore me"); Console.ReadLine(); ... 

That is likely preventing the service from responding properly to indicate it is started.

Sign up to request clarification or add additional context in comments.

1 Comment

I removed the lines, but same result

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.