-
March 30th, 2004, 04:13 PM
#1
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
-
March 30th, 2004, 06:44 PM
#2
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.
-
April 1st, 2004, 05:18 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|