Windows Service startup failure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon

    Windows Service startup failure

    Hi there

    I've written a windows service that works OK, apart fom the fact that if it were to fail during startup, I'm not sure of the best way to handle it. If I let the exception fall thru' from my OnStart() method, the exception is reported in the event log and the service is not marked as started. But the exception message is messy and I want to catch it and report it cleanly if I can. If I catch it myself, report it then continue (without re-throwing), the service is marked as started, which isn't what I want.

    Is there any way I can catch the exception for reporting myself, then indicate to the SCM that it hasn't started, without relying on 'fall through' exceptions to inidictate this?

    Thanks

    Jon

  • Michael Riggio

    #2
    Re: Windows Service startup failure

    You should be able to catch the exception in your OnStart method, process
    accordingly, and then throw the same exception or a new less messy exception
    for the SCM to deal with.

    "Jon" <anonymous@disc ussions.microso ft.com> wrote in message
    news:D0004D41-E29F-4A28-9E57-332F86636329@mi crosoft.com...[color=blue]
    > Hi there
    >
    > I've written a windows service that works OK, apart fom the fact that if[/color]
    it were to fail during startup, I'm not sure of the best way to handle it.
    If I let the exception fall thru' from my OnStart() method, the exception is
    reported in the event log and the service is not marked as started. But the
    exception message is messy and I want to catch it and report it cleanly if I
    can. If I catch it myself, report it then continue (without re-throwing),
    the service is marked as started, which isn't what I want.[color=blue]
    >
    > Is there any way I can catch the exception for reporting myself, then[/color]
    indicate to the SCM that it hasn't started, without relying on 'fall
    through' exceptions to inidictate this?[color=blue]
    >
    > Thanks
    >
    > Jon
    >[/color]


    Comment

    Working...