CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Nov 2009
    Posts
    12

    Windows service staying in "Starting" status!

    Hi there this is my first post on the C# Forums. Therefor i will first introduce myself a little bit:

    My name is Haye, and i'm a student from the Netherlands, being in the last schoolyear. I like friedpotatoes and since a short period of time i started programming in C#.

    So here's my problem:

    I have a multi-threaded program wich Polls several devices through a small box running a Nagios setup. The progam needs to be started Manually, so when its running on a server, and the server crashes, big problems will occur since the program will not restart again.

    The above part is the main reason why i've decided to create a windows Service. Now, i've already made the program to work as a windows service, but whenever i start the Service, a progressbar pops-up telling me that windows is attempting to start the service, eventually when the progressbar is fully-filled, another pop-up comes up telling me that the application did not respond in a fashionaly time.

    All the popups dissapear, and in the services.msc screen the status of my service is still on "Starting" from that point i need to do a reboot before i can stop the service.

    Although the above happens, the program does work correctly, since my database gets updated and log files are created as they would without it being a Service-based program!


    I hope someone can help me out!

    Greetings,
    Haye Haverbus

  2. #2
    Join Date
    Nov 2009
    Posts
    12

    Re: Windows service staying in "Starting" status!

    Sorry for the double post, but here's some additional information about the app:

    Made in Visual Studio 2008, It's a console application, and it is using SQL Connections with a database.

  3. #3
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Re: Windows service staying in "Starting" status!

    Have you made a console appication ? or is it a proper windows service ?
    Does it show error message saying that it cannot start service from command line ? when you try to open it directly ?
    Regards,
    MMH
    Rate my post if you find it usefull.

  4. #4
    Join Date
    Nov 2009
    Posts
    12

    Re: Windows service staying in "Starting" status!

    Quote Originally Posted by MMH View Post
    Have you made a console appication ? or is it a proper windows service ?
    Does it show error message saying that it cannot start service from command line ? when you try to open it directly ?
    Yes, i made a Console application. Running the application as a non-service application works fine. And the error message only tells me that the application did not respond in time (about 2 mins)

    It looks like Windows does not understand wether the program is running or not!

    Thanks for your reply!

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Windows service staying in "Starting" status!

    Quote Originally Posted by HausNL View Post
    Yes, i made a Console application. ...
    It looks like Windows does not understand wether the program is running or not!
    Why don't you create a Windows service project and move your code into that?

  6. #6
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Re: Windows service staying in "Starting" status!

    Quote Originally Posted by HausNL View Post
    It looks like Windows does not understand wether the program is running or not!
    Mate, when you try to run the service directly just by double clicking it, do you see any error message poping up ? saying you cannot run service from command line ?

    Also, can you please tell us how did you registered the windows service ?
    Last edited by MMH; November 11th, 2009 at 11:13 AM.
    Regards,
    MMH
    Rate my post if you find it usefull.

  7. #7
    Join Date
    Nov 2009
    Posts
    12

    Re: Windows service staying in "Starting" status!

    @Arjay: Doesn't work either, already tryed that, forgot to mention it.

    @MMH: If i click the service directly it indeed tells me the following:

    Windows Service Start Failure
    "
    Cannot start the service from the command line debugger. A windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command."

    I've installed the service as following.

    1. Copyed the Installutil.exe to my Debug folder.
    2. Run CMD, navigate to the Debug folder and use this command: installutil qiboxengine.exe
    3. Then the CMD Console prompts me that the service is installed succesfully.

    and from there move on to Start >> Run >> services.msc >> and then start the service... But then again it works, but windows does not notice it, so Windows seems to be waiting for some reply of the program or something!

    Since the application is a Console application, i've already gone into the properties and told windows that the service may interact with the desktop resulting in the exact same way...

    Then i thought, well maybe it's the fact that there is alot of output in the console, and maybe windows does not want this, so i've created a test app which writes to a file every 5 seconds + outputting data in a Console window.

    But this service runs fine, and can be stopped also...

    Thanks for the reply's!

  8. #8
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Re: Windows service staying in "Starting" status!

    Have you tried installing your service on some other machine ?
    Also, you can try with the following command

    Code:
     sc create Service1 C:\abc\service.exe
    Where "Service1" is your service name,

    Type the above command in cmd.exe

    Try with the above two things and let us know...
    Regards,
    MMH
    Rate my post if you find it usefull.

  9. #9
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: Windows service staying in "Starting" status!

    You say you have a console app that spits out info to the command window. Is this in some sort of loop? Services are not like console applications. Their starting and stopping is controlled by external processes.

    If you have a loop, is it in the OnStart method. If so, you will need to work out a different method for doing your processing, because the OnStart method never returns until your loop finishes.

    You would probably need to set up some timers to run your function over and over until the OnStop method is called.

  10. #10
    Join Date
    Nov 2009
    Posts
    12

    Re: Windows service staying in "Starting" status!

    Quote Originally Posted by MMH View Post
    Have you tried installing your service on some other machine ?
    Also, you can try with the following command

    Code:
     sc create Service1 C:\abc\service.exe
    Where "Service1" is your service name,

    Type the above command in cmd.exe

    Try with the above two things and let us know...
    MMH Thanks for you reply, tryed both your methots, resulting in the exact same problem!


    @ sotasty

    Yes there are definately loops in the program, but not in the Start event. The start event opens database connections, gets information, closes it and the passes the information on to different classes within the program, these classes process the data (opening other DB connections, adding information etc etc). In the start event everything just gets activated so that the processing can start!

    here is the code being called in the OnStart event:

    i'll post the start code in the next reply.

    Greets Haye
    Last edited by HausNL; November 12th, 2009 at 09:36 AM. Reason: Forgot some Code!

  11. #11
    Join Date
    Nov 2009
    Posts
    12

    Re: Windows service staying in "Starting" status!

    Code:
    Code:
     public void start()
            {
    
                // iedreen laten weten dat we gaan beginnen
                this.inBedrijf = true;
                this.info(2, "Engine is started.");
    
                //Haal de connectiestring op uit het register
                RegistryKey dbkey = Registry.LocalMachine.CreateSubKey("Software\\QI\\QIengine");
                string con = (string)dbkey.GetValue("Connection");
    
                this.db = new qboxserver.altijd.db(this, con);
    
                qboxserver.inspoelen.qibox asd = new qboxserver.inspoelen.qibox();
    
    
                //string herrie = "printf '#update\n\n" + asd.maakConfig(this, 3) + "' > /usr/local/nagios/etc/objects/qi.cfg";
                //Console.WriteLine(herrie);
                //Console.WriteLine("zogenaamd klaar met inspoelen");
                // haal de monitors gegevens op uit de database & plaats ze intern
    
                this.gegevens = new qboxserver.gegevens.gegevens(this);
    
                controleerNieuweSettings = new Thread(new ThreadStart(this.gegevens.opVrissenKeepAlive));
                controleerNieuweSettings.IsBackground = true;
                controleerNieuweSettings.Start();
              
    
              //  this.gegevens.devices[3].uitvoeren.Add(1, herrie);
              //  start de ssh , Opletten !! Dit wordt een aparte thread
    
              this.polling = new polling.polling(this);
    
              trdPoll = new Thread(new ThreadStart(polling.keepAlive));
              trdPoll.IsBackground = true;
              trdPoll.Start();
    
             
    
    
                // start de controle , Opletten !! Dit wordt een aparte thread
                this.aflopen = new qboxserver.afhandeling.aflopen(this);
    
    
              
    
    
                trdAfhandeling = new Thread(new ThreadStart(aflopen.keepAlive));
                trdAfhandeling.IsBackground = true;
                trdAfhandeling.Start();
    
    
                trdStatsAfhandeling = new Thread(new ThreadStart(aflopen.keepStaticsAlive));
                trdStatsAfhandeling.IsBackground = true;
                trdStatsAfhandeling.Start();
    
                
    
                // afsluiten
                this.gezondheid();
                this.db.afsluiten();
            }
    So the above code is my OnStart event.
    Last edited by HausNL; November 12th, 2009 at 09:40 AM. Reason: Forgot Note:

  12. #12
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: Windows service staying in "Starting" status!

    Code:
                this.gezondheid();
                this.db.afsluiten();
    What do these functions do? When they are executed, do they return immediately, or does it take them some time to return control to the next statement?

  13. #13
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Windows service staying in "Starting" status!

    Quote Originally Posted by HausNL View Post
    @Arjay: Doesn't work either, already tryed that, forgot to mention it.
    Okay, have you tried to create a service and attempted to start it before moving your code into it?

    This should take about 15 minutes to create the new service project, add the installer, and register it with installutil.exe from the command line.

  14. #14
    Join Date
    Nov 2009
    Posts
    12

    Re: Windows service staying in "Starting" status!

    @sotasty

    The function gezondheid, is actually a while loop based on a boolean. So i guess this loop is causing the problem, i will run some tests to see if this is the problem.

    @arjay

    Haven't tryed that, but whats the purpose of doing that?

    Greetings and thanks for the reply's

    edit:
    Hi there,

    @sotasty
    I was running the service without the gezondheid(); function, and guess what! It started normally! the only problem is that it doesn't do the all the work anymore simply because a function is missing, now i'm gonna try and find a workaround for this problem.

    Thanks for you reply's! Dont close the topic yet, it's ALMOST solved!

    Greetings Haye
    Last edited by HausNL; November 13th, 2009 at 03:21 AM. Reason: Ran some tests!

  15. #15
    Join Date
    Nov 2009
    Posts
    12

    Re: Windows service staying in "Starting" status!

    Guys i have found the solution!

    Since the service was always in start mode because of the fact that windows was waiting for the loop to end. I've made a public bool and at the initialisation set it to False. So whenever the start event i called, the public bool is set to True, and windows seems to accept it now :P

    Thanks for all your help guys, couldn't do it without you!

    Greetings,
    Haye!

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured