www.pudn.com > OracleServiceManager.zip > ServicePaused.cs


using System; 
using System.Diagnostics; 
using System.ServiceProcess; 
 
namespace kae.ServiceStatePublisher 
{ 
	///  
	/// ServicePaused is a concrete ServiceState representing the  
	/// ServiceController state of paused.  As a singleton, only  
	/// one instance of this class is needed for the application. 
	///  
	public class ServicePaused : ServiceState 
	{ 
		private static ServicePaused _instance; 
 
		static ServicePaused() 
		{ 
			lock (typeof(ServicePaused)) 
			{ 
				if (_instance == null) 
					_instance = new ServicePaused(); 
			} 
		} 
 
		public static ServicePaused Instance 
		{ 
			get { return _instance; } 
		} 
 
		public override void Start( ServiceContext context) 
		{ 
			Continue( context); 
		} 
 
		public override void Continue( ServiceContext context) 
		{ 
			try 
			{ 
				context.Controller.Continue(); 
				context.Controller.WaitForStatus( ServiceControllerStatus.Running, new TimeSpan(0,0,30)); 
				ChangeState( context, ServiceRunning.Instance); 
			} 
			catch (TimeoutException te) 
			{ 
				LogError( te.Message, EventLogEntryType.Warning); 
				throw te; 
			} 
		} 
 
		public override void Stop( ServiceContext context) 
		{ 
			try 
			{ 
				context.Controller.Stop(); 
				context.Controller.WaitForStatus( ServiceControllerStatus.Stopped, new TimeSpan(0,0,30)); 
				ChangeState( context, ServiceStopped.Instance); 
			} 
			catch (TimeoutException te) 
			{ 
				LogError( te.Message, EventLogEntryType.Warning); 
				throw te; 
			} 
		} 
 
		public override string Status 
		{ 
			get { return "Paused"; } 
		} 
 
		public override bool IsPaused 
		{ 
			get { return true; } 
		} 
	} 
}