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 Services and Shutdown

Windows Services and Shutdown

Scheduled Pinned Locked Moved C#
questioncsharpdatabasesql-serversysadmin
2 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
    Jesse Squire
    wrote on last edited by
    #1

    Hi All, Any insight into the following would be greatly appreciated. Onto the problem... Here's the quick version of what I'm looking to answer:

    • What is the order in which the services are stopped?
    • Is there a differentiation between system services and user/application services?
    • If so, are system services treated differently than user/application services?
    • Is there a way that we can control the shutdown process enough to enable our service to terminate as it was intended?
    • Is there any Microsoft documentation availible that addresses Windows services and system shutdown?

    Here's the background The application in question is being written in C#, and implemented as a Windows service. When the service reads data from the mainframe (MACS), it has no option but to do so destructively. Once the data is read into memory, it no longer exists elsewhere until the service massages the data and deposits it into SQL Server 2000. There is no known way to read the data in a non-destructive manner, nor to "peek" at the data without performing the destructive read... this is an area that we're also pursuing. The service consists of two threads. The main thread exists only to listen for, and respond to, Service Control Manager (SCM) requests. When the SCM requests a Start, the main thread creates a worker thread (priority:normal) to perform the needed tasks. The worker thread performs these tasks using an object that both it and the main thread hold a reference to. When the SCM requests a Stop, the service signals the worker thread by calling a thread-safe method on the object. The main thread joins the worker thread, in order to remain alive until completion. The worker thread will terminate when all of the data in memory has been safely written to SQL Server, and the external connections have been closed. Here's the problem The problem that we're having with the service implementation is related to the computer being shutdown or restarted. The service has programmatically requested to receive notification of the system shutdown event (by setting System.ServiceProcess.ServiceBase.CanShutdown property to true). When the service is notified of the shutdown request (through the OnShutdown()method), the main thread signals the worker by calling a thread-safe method on the shared object. The main thread joins the worker thread, in order to remain alive until completion. The worker thread terminates when all o

    D 1 Reply Last reply
    0
    • J Jesse Squire

      Hi All, Any insight into the following would be greatly appreciated. Onto the problem... Here's the quick version of what I'm looking to answer:

      • What is the order in which the services are stopped?
      • Is there a differentiation between system services and user/application services?
      • If so, are system services treated differently than user/application services?
      • Is there a way that we can control the shutdown process enough to enable our service to terminate as it was intended?
      • Is there any Microsoft documentation availible that addresses Windows services and system shutdown?

      Here's the background The application in question is being written in C#, and implemented as a Windows service. When the service reads data from the mainframe (MACS), it has no option but to do so destructively. Once the data is read into memory, it no longer exists elsewhere until the service massages the data and deposits it into SQL Server 2000. There is no known way to read the data in a non-destructive manner, nor to "peek" at the data without performing the destructive read... this is an area that we're also pursuing. The service consists of two threads. The main thread exists only to listen for, and respond to, Service Control Manager (SCM) requests. When the SCM requests a Start, the main thread creates a worker thread (priority:normal) to perform the needed tasks. The worker thread performs these tasks using an object that both it and the main thread hold a reference to. When the SCM requests a Stop, the service signals the worker thread by calling a thread-safe method on the object. The main thread joins the worker thread, in order to remain alive until completion. The worker thread will terminate when all of the data in memory has been safely written to SQL Server, and the external connections have been closed. Here's the problem The problem that we're having with the service implementation is related to the computer being shutdown or restarted. The service has programmatically requested to receive notification of the system shutdown event (by setting System.ServiceProcess.ServiceBase.CanShutdown property to true). When the service is notified of the shutdown request (through the OnShutdown()method), the main thread signals the worker by calling a thread-safe method on the shared object. The main thread joins the worker thread, in order to remain alive until completion. The worker thread terminates when all o

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      AFAIK, you should register you service as depending on the SQL Server service, so the OS can properly determine the startup sequence. Actually, you should register any of your service's dependencies. Probably, this information is needed for the right shutdown sequence too (my conclusion here). On .NET, you have the ServicesDependedOn property on the ServiceInstaller. Another remark: by default, if your shutdown process takes more than 20s, Windows will presume your service is hung up and probably will kill your process. There's a registry entry for configuring this time. [edit]Debugging tip: Use Trace.Writeline or a interop call to OutputDebugString and use dbgview or dbmon to see it.[/edit] I see dumb people

      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