Link to home
Start Free TrialLog in
Avatar of GouthamAnand
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"))
            {
                return;
            }

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

http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.onstart.aspx
http://msdn.microsoft.com/en-us/library/aa984464(v=vs.71).aspx
What are you trying to do when its DEV?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

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

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
GouthamAnand

ASKER

Thank You
NP. Glad to help :)