CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Posts
    13

    How to recognize a STOP in Windows Services

    I am writing a Service in 'C' which has lots of database activity. When the user requests to STOP the Service (within the Service Control Manager) the program simply halts. It does not matter what it is in the middle of doing.

    How do I recognize that a STOP has been requested? I need this so I can shutdown the service gracefully.

    There is a nice example of a Service posted on this web-site and it shows how to pause or stop a service but both of these happen instantly without any warning.

    Any help is greatly appreciated!

    Mattl

  2. #2
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    you call RegisterServiceCtrlHandler(...) (in your ServiceMain(...)and pass it your Handler function, you process the stop inside of your handler function.
    Can you post the link to the article in question so I can look at what you are referencing.

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How to recognize a STOP in Windows Services

    Originally posted by mattl
    I am writing a Service in 'C' which has lots of database activity. When the user requests to STOP the Service (within the Service Control Manager) the program simply halts. It does not matter what it is in the middle of doing.

    How do I recognize that a STOP has been requested?
    STOP request for service looks like getting SERVICE_CONTROL_STOP control message via its control handler routine.
    I need this so I can shutdown the service gracefully.
    Service been requested to sop itself has to set its state to SERVICE_STOP_PENDING, to initiate a cleanup procedure and after cleanup ends it has to set its state to SERVICE_STOP notifying the system it's done. It has about 30 seconds (since SERVICE_CONTROL_STOP been emitted) to do it before system will decide to kill it as hanging process. If the service needs more than 30 seconds it has to use checkpoint mechanism.
    There is a nice example of a Service posted on this web-site and it shows how to pause or stop a service but both of these happen instantly without any warning.
    There is a really nice book on this questions:
    Jeffrey Richter, Programming Server-Side Applications for MS Windows 2000. Spend a bit of your money and your time on it - and you'll never regret for money and time you've spent (if you gonna dive into windows service programming more than once).
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured