How can a service control its own state?
<p>I have a standard windows server that inherits from the ServiceBase class.</p>

<p>On the OnStart method I want to check for certain conditions before I get to the main purpose of what my service does.</p>

<p>For example:</p>

<pre><code>protected override void OnStart(string[] args)
{
  if (condition == false)
  {
    EventLog.WriteEntry("Pre-condition not met, service was unable to start");

    // TODO: Convert service state to "Stopped" because my precondition wasn't met
    return;
  }

  InnitializeService();
}
</code></pre>

<p>Anybody have a good example for how a service can control its own state?</p>
