Service 错误1053:服务未在visual studio 2015上及时响应启动或控制请求
我使用C#创建了一个windows服务,如下所示Service 错误1053:服务未在visual studio 2015上及时响应启动或控制请求,service,windows-services,windows-10,Service,Windows Services,Windows 10,我使用C#创建了一个windows服务,如下所示 public partial class Housekeeping : ServiceBase { #region Fields private ManualResetEvent _ResetEvent = new ManualResetEvent(false); private RegisteredWaitHandle _RegisteredWaitHandle; private long _Interval =
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();;
}
}
基本上
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);
}
}
静态类程序
{
///
///应用程序的主要入口点。
///
静态void Main()
{
ServiceBase[]ServicesToRun;
ServicesToRun=新的ServiceBase[]
{
新内务管理()
};
ServiceBase.Run(ServicesToRun);
}
}
我使用InstallUtil.exe安装了WS,但是当我尝试启动WS时,我得到了这个错误“错误1053:服务没有及时响应启动或控制请求”。我到处浏览,但所有的解决方案都是针对WindowsServer2003问题的,我正在运行Windows10
如何解决此问题?上次我看到此问题时,通过将编译选项从“Debug”更改为“Release”解决了此问题。上次我看到此问题时,通过将编译选项从“Debug”更改为“Release”解决了此问题。最可能的原因是Main()函数中存在问题。请显示其余的代码。Harry Johnston,我更新了我正在使用的代码。谢谢。我对.NET ServiceBase类不是很熟悉,但我觉得这个看起来不错。我唯一能建议的是,构造函数可能由于某种原因没有返回-可能需要进行一些日志记录,以查看您是否正在访问
ServiceBase.Run
和/或是否实际调用了OnStart()。最可能的原因是Main()函数中存在问题。请显示其余的代码。Harry Johnston,我更新了我正在使用的代码。谢谢。我对.NET ServiceBase类不是很熟悉,但我觉得这个看起来不错。我唯一能建议的是,构造函数可能出于某种原因没有返回—可能需要进行一些日志记录,以查看您是否正在访问ServiceBase.Run
和/或是否实际调用了OnStart()。