Visual C# Developer Center > Visual C# Forums > Visual C# General > Window service | validation before stopping it
Ask a questionAsk a question
 

AnswerWindow service | validation before stopping it

  • Thursday, November 05, 2009 6:30 AMpavan_kakumani Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi, I have a doubt regarding stopping a window service. Before stopping a window service, i want to check whether the particular service is servicng any requests or not. If i am stopping the service without doing the above validation, all the requests presently serving by the window service will be failed. So i need to do a validation before stopping the window service. After doing a small search, i got "canstop" property in "System.ServiceProcess" .Net Classes. Is it the right property to fulfill my validation scenario? Please guide me the right way to implement the validation logic before stopping the window service. Thanks in Advance, Pavan

Answers

  • Saturday, November 07, 2009 3:08 PMChao KuoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello, Pavan
    Yes, you could rely on ServiceProvider.Canstop property. And you don't need to worry about stop a service that stop a particular service that is service an request. If you stop a service that could not be stopped, you would caught a exception with an error message  "Cannot stop *** service on computer ***.
    Thanks
    Chao

All Replies

  • Saturday, November 07, 2009 3:08 PMChao KuoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello, Pavan
    Yes, you could rely on ServiceProvider.Canstop property. And you don't need to worry about stop a service that stop a particular service that is service an request. If you stop a service that could not be stopped, you would caught a exception with an error message  "Cannot stop *** service on computer ***.
    Thanks
    Chao