Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Windows service failed to start.

Windows service failed to start.

Scheduled Pinned Locked Moved C#
csharphelp
13 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Add try-catch block to method OnStart. See what happened in catch block.

    A Offline
    A Offline
    Anil Veeraghattapu 4
    wrote on last edited by
    #3

    alright. lemme try and get back to you.

    1 Reply Last reply
    0
    • L Lost User

      Add try-catch block to method OnStart. See what happened in catch block.

      A Offline
      A Offline
      Anil Veeraghattapu 4
      wrote on last edited by
      #4

      yes i put all the code of the Onstart event in try catch block. its no use. i am getting the same error message when i tried to start the service from the service explorer thanks Anil Veeraghattapu.

      L D 2 Replies Last reply
      0
      • A Anil Veeraghattapu 4

        I am creating a windows service using c#.net 3.5 i created installer file to install it. it was installed successfully. when i tried to start the service from the service explorer it showing the below error instead of starting the service "some services stop automatically if they are not in use by other programs or services". Please help me out. Thanks Anil Veeraghattapu.

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #5

        Have you run it under the debugger yet?

        .45 ACP - because shooting twice is just silly
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

        A 1 Reply Last reply
        0
        • A Anil Veeraghattapu 4

          yes i put all the code of the Onstart event in try catch block. its no use. i am getting the same error message when i tried to start the service from the service explorer thanks Anil Veeraghattapu.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #6

          the problem is : you got an exception in OnStart. You must find the exception, what it is.

          try
          {
          ...
          }
          catch(Exception ex)
          {
          File.WriteAllText(@"c:\error.txt", ex.ToString());
          }

          If you start the service and got an error, then look at c:\error.txt. That is the error.

          A 1 Reply Last reply
          0
          • realJSOPR realJSOP

            Have you run it under the debugger yet?

            .45 ACP - because shooting twice is just silly
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

            A Offline
            A Offline
            Anil Veeraghattapu 4
            wrote on last edited by
            #7

            the service a'nt got started my friend. i am unable to attach it to debugger. Thanks Anil Veeraghattapu.

            realJSOPR 1 Reply Last reply
            0
            • A Anil Veeraghattapu 4

              I am creating a windows service using c#.net 3.5 i created installer file to install it. it was installed successfully. when i tried to start the service from the service explorer it showing the below error instead of starting the service "some services stop automatically if they are not in use by other programs or services". Please help me out. Thanks Anil Veeraghattapu.

              G Offline
              G Offline
              Gonzalo Cao
              wrote on last edited by
              #8

              In the event log you can see further information, if there's an exception you will be able to see it there as well.

              A 1 Reply Last reply
              0
              • A Anil Veeraghattapu 4

                yes i put all the code of the Onstart event in try catch block. its no use. i am getting the same error message when i tried to start the service from the service explorer thanks Anil Veeraghattapu.

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #9

                Anil Veeraghattapu 4 wrote:

                i put all the code of the Onstart event

                There is your problem. The general layout of a Service is, in OnStart, you are expected to start a seperate thread that handles your main service code loop, such a listeners or some kind of polling loop, ... This releases OnStart and returns control back to the Service Control Manager. In OnStop, you shutdown this loop as appropriate and let the thread stop gracefully. Putting all of your code in OnStart gives you exactly the error message your getting because OnStart never returns control back to the SCM within the default 30 seconds the SCM expects OnStart to return.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008
                But no longer in 2009...

                1 Reply Last reply
                0
                • A Anil Veeraghattapu 4

                  I am creating a windows service using c#.net 3.5 i created installer file to install it. it was installed successfully. when i tried to start the service from the service explorer it showing the below error instead of starting the service "some services stop automatically if they are not in use by other programs or services". Please help me out. Thanks Anil Veeraghattapu.

                  R Offline
                  R Offline
                  R Giskard Reventlov
                  wrote on last edited by
                  #10

                  You can debug services using the AndersonImes.ServiceProcess dll which works really well. Had a quick look but can't find it so you may have to contact[^] him directly: well worth having in your toolkit.

                  me, me, me "The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!" Larry Niven nils illegitimus carborundum

                  1 Reply Last reply
                  0
                  • L Lost User

                    the problem is : you got an exception in OnStart. You must find the exception, what it is.

                    try
                    {
                    ...
                    }
                    catch(Exception ex)
                    {
                    File.WriteAllText(@"c:\error.txt", ex.ToString());
                    }

                    If you start the service and got an error, then look at c:\error.txt. That is the error.

                    A Offline
                    A Offline
                    Anil Veeraghattapu 4
                    wrote on last edited by
                    #11

                    Thanks i find the exception in the text file. you did a great help. the problem is it was a fromat exception throw by a log control when i tried to log somethin in the on start event Thanks Anil Veeraghattapu.

                    1 Reply Last reply
                    0
                    • G Gonzalo Cao

                      In the event log you can see further information, if there's an exception you will be able to see it there as well.

                      A Offline
                      A Offline
                      Anil Veeraghattapu 4
                      wrote on last edited by
                      #12

                      Yes you are right. it was some format exception i find it in the event log too. Thanks for your help Thanks Anil veeraghattapu.

                      1 Reply Last reply
                      0
                      • A Anil Veeraghattapu 4

                        the service a'nt got started my friend. i am unable to attach it to debugger. Thanks Anil Veeraghattapu.

                        realJSOPR Offline
                        realJSOPR Offline
                        realJSOP
                        wrote on last edited by
                        #13

                        Wrong. Put a breakpoint at the top of the Start)( method.

                        .45 ACP - because shooting twice is just silly
                        -----
                        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                        -----
                        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups