|
using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
namespace kae.ServiceStatePublisher
{
/// <summary>
/// ServiceStopped is a concrete ServiceState representing the
/// ServiceController state of stopped. As a singleton, only
/// one instance of this class is needed for the application.
/// </summary>
public class ServiceStopped : ServiceState
{
private static ServiceStopped _instance;
static ServiceStopped()
{
lock (typeof(ServiceStopped))
{
if (_instance == null)
_instance = new ServiceStopped();
}
}
public static ServiceStopped Instance
{
get { return _instance; }
}
public override void Start( ServiceContext context)
{
try
{
context.Controller.Start();
context.Controller.WaitForStatus( ServiceControllerStatus.Running, new TimeSpan(0,0,30));
ChangeState( context, ServiceRunning.Instance);
}
catch (TimeoutException te)
{
LogError( te.Message, EventLogEntryType.Warning);
throw;
}
}
public override string Status
{
get { return "Stopped"; }
}
public override bool IsStopped
{
get { return true; }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Dwight D. Eisenhower wrote: "In battle, I believe plans are useless; however, planning is indespensable."
Hmm, perhaps he was an early adopter of agile beliefs?!