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. Interrupting service startup

Interrupting service startup

Scheduled Pinned Locked Moved C#
csharphelptutorialquestioncode-review
4 Posts 3 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.
  • F Offline
    F Offline
    Fred2834
    wrote on last edited by
    #1

    Hello, I am writing my first Windows Service in .Net (4.0, VS2010), and I am getting the results I expect, but there is one thing I would like to optimize, but do not know how.. and googlin' it has been infructuous so far.. Basically, I want to know what I have to write in the OnStart method to actually make sure the service does not go into "running" mode if something fails (ex: loading the config). It's all ok when everything loads well, but I have no idea how to abort the startup when an error is encountered. Any idea ? Thanks in advance, Best regards, Fred

    R D 2 Replies Last reply
    0
    • F Fred2834

      Hello, I am writing my first Windows Service in .Net (4.0, VS2010), and I am getting the results I expect, but there is one thing I would like to optimize, but do not know how.. and googlin' it has been infructuous so far.. Basically, I want to know what I have to write in the OnStart method to actually make sure the service does not go into "running" mode if something fails (ex: loading the config). It's all ok when everything loads well, but I have no idea how to abort the startup when an error is encountered. Any idea ? Thanks in advance, Best regards, Fred

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Fred2834 wrote:

      I want to know what I have to write in the OnStart method to actually make sure the service does not go into "running" mode if something fails (ex: loading the config).

      I would assume throwing an exception would suffice. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • F Fred2834

        Hello, I am writing my first Windows Service in .Net (4.0, VS2010), and I am getting the results I expect, but there is one thing I would like to optimize, but do not know how.. and googlin' it has been infructuous so far.. Basically, I want to know what I have to write in the OnStart method to actually make sure the service does not go into "running" mode if something fails (ex: loading the config). It's all ok when everything loads well, but I have no idea how to abort the startup when an error is encountered. Any idea ? Thanks in advance, Best regards, Fred

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

        There's various ways of doing it, with equally various opinions on what's appropriate. The quick'n'dirty method is to set the this.ExitCode to a non-zero value specifying what the Win32 error was and then call the this.Stop() method.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        F 1 Reply Last reply
        0
        • D Dave Kreskowiak

          There's various ways of doing it, with equally various opinions on what's appropriate. The quick'n'dirty method is to set the this.ExitCode to a non-zero value specifying what the Win32 error was and then call the this.Stop() method.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          F Offline
          F Offline
          Fred2834
          wrote on last edited by
          #4

          .. geez, should have thought about that! Thanks ! :-D

          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