0

I have below scenario and i am not sure about 3rd point

  1. Sevice1 one is running
  2. it encounter some exception i need to stop the service1 and restart it again
  3. Can we do this stop and restart service1 by writing Restart code in Service1 itself
  • A service can't restart itself, no. However if it's a windows service, you can configure the service's settings to attempt to restart if it fails. The service needs to exit with an error code, so that windows can detect it. You can google more about it, I forget the specifics right now. – ADyson Dec 18 '20 at 13:46

1 Answers1

0

Here is a ServiceController class article written on windows services; Ways of starting, stopping or restarting are explained. Or try this topic

You can also call the command below to do this

System.Diagnostics.Process.Start("net", "stop IISAdmin");
System.Diagnostics.Process.Start("net", "start IISAdmin");