I made a windows service using C# as follow
public partial class Housekeeping : ServiceBase
{
#region Fields
private ManualResetEvent _ResetEvent = new ManualResetEvent(false);
private RegisteredWaitHandle _RegisteredWaitHandle;
private long _Interval = 60000;
private Logger _Logger;
#endregion
#region Constructors
public Housekeeping()
{
InitializeComponent();
_Interval = _Interval * Convert.ToInt32(ConfigurationManager.AppSettings["RunningInterval"]);
_Logger = new Logger();
}
#endregion
#region Properties
#endregion
#region Behaviors
public void Housekeep(object state, bool timeout)
{
try
{
// my code
}
catch (Exception ex)
{
// my code
}
}
protected override void OnStart(string[] args)
{
_RegisteredWaitHandle = ThreadPool.RegisterWaitForSingleObject(_ResetEvent, new WaitOrTimerCallback(Housekeep), null, _Interval, false);
}
protected override void OnStop()
{
}
protected override void OnContinue()
{
base.OnContinue();
}
protected override void OnPause()
{
base.OnPause();;
}
}
and on the main
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Housekeeping()
};
ServiceBase.Run(ServicesToRun);
}
}
I Installed the WS using InstallUtil.exe, but when I tried to start the WS I got this error "error 1053: the service did not respond to the start or control request in a timely fashion". I surfed around but all the solution are for a windows server 2003 issue and I'm running Windows 10.
How can I solve this issue?
ServiceBase.Run
and/or whether OnStart() is actually being called. – Harry Johnston