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. .NET (Core and Framework)
  4. How to announce Windows Service Manager, that service fails (Recovery Options)

How to announce Windows Service Manager, that service fails (Recovery Options)

Scheduled Pinned Locked Moved .NET (Core and Framework)
tutorialquestion
3 Posts 2 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.
  • J Offline
    J Offline
    Jan Lehmann
    wrote on last edited by
    #1

    Hello, the Windows Service Manager provides some recovery options. In the properties of a service, you can select the computer's response if the service fails. For example, First failure >> Restart the Service. How can I announce the Windows Service Manager, that my own service fails, so that the recovery options start the work? Has anyone a code example? Thanks in advance Best regards, Jan Lehmann [Germany]

    I 2 Replies Last reply
    0
    • J Jan Lehmann

      Hello, the Windows Service Manager provides some recovery options. In the properties of a service, you can select the computer's response if the service fails. For example, First failure >> Restart the Service. How can I announce the Windows Service Manager, that my own service fails, so that the recovery options start the work? Has anyone a code example? Thanks in advance Best regards, Jan Lehmann [Germany]

      I Offline
      I Offline
      ian mariano
      wrote on last edited by
      #2

      If your service throws an unhandled exception, the SCM will handle it. If your service terminates abruptly (such as it's process being killed), the SCM will handle it.

      //  c#
      Process.GetCurrentProcess().Kill();
      

      A really good way to get Windows to know your app failed most heinously is to use Interop and RaiseException and pass EXCEPTION_NONCONTINUABLE for the dwExceptionFlags parameter.

      Ian Mariano - Bliki | Blog
      "We are all wave equations in the information matrix of the universe" - me

      1 Reply Last reply
      0
      • J Jan Lehmann

        Hello, the Windows Service Manager provides some recovery options. In the properties of a service, you can select the computer's response if the service fails. For example, First failure >> Restart the Service. How can I announce the Windows Service Manager, that my own service fails, so that the recovery options start the work? Has anyone a code example? Thanks in advance Best regards, Jan Lehmann [Germany]

        I Offline
        I Offline
        ian mariano
        wrote on last edited by
        #3

        It's also probably a very good idea to log the service failure in the Windows Event Log, or publish it to WMI.

        //   c#  panic(), expects message as a string parameter
        EventLog  log = new EventLog(...);
        
        log.Write(message, EventLogEntryType.Error);
        Process.GetCurrentProcess().Kill();
        

        It should be noted that forcibly terminating an application without at least attempting a graceful shutdown / release of resources is a bad idea. If possible, cleanup what you can before Killing the process.

        Ian Mariano - Bliki | Blog
        "We are all wave equations in the information matrix of the universe" - me

        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