Link to home
Start Free TrialLog in
Avatar of GouthamAnand

asked on

Windows Service OnStart() and OnStop()

My windows service is having the below IF condition in OnStart() as first line.

if (ConfigurationSettings.AppSettings["Environment"].ToString().ToUpper().Equals("DEV"))

If this IF condition becomes true, does it stop running? does it exicute OnStop() method?

Or does it continue running?

Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

These are only actions:
OnStart: to initialize your service
OnStart: to do clean up/ free resources in your service when the service is stopped by/from Windows.
They will not stop the service from running, it continues executing whatever your service code is
What are you trying to do when its DEV?
Avatar of kaufmed
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

The short answer to your question is:

    Yes. If you haven't already spawned the thread or timer, then when you call 'return' from within OnStart(), your service will be stopped. OnStop() will not be called since it will appear to the system that the service never started.
Avatar of GouthamAnand


Thank You
NP. Glad to help :)