我想用Visual Studio创建Windows服务应用程序。启动服务时出现此错误:
错误1053,服务未响应启动或控制请求 及时
所以我删除了代码,仍然遇到此错误。也许我错过了一些设置,所以这是我要复制的项目:
首先使用Visual Studio创建Windows Service App(C#)
将体系结构设置为x86。
将输出路径设置为另一个目录,我的目录是 C:\ Program Files(x86)\ Kofax \ CaptureSS \ ServLib \ Bin 。
将所需的dll添加到项目中,例如 PDFSharp
将Program.cs更新为调试模式( RuntimeService 是我的服务文件)
private static void Main()
{
#if DEBUG
new RuntimeService().RunDebugMode();
Thread.Sleep(TimeSpan.FromDays(1));
#else
ServiceBase.Run(new RuntimeService());
#endif
}
我的 RuntimeService.cs 包含以下代码
public RuntimeService()
{
InitializeComponent();
}
public void RunDebugMode()
{
OnStart(null);
}
protected override void OnStart(string[] args)
{
// nothing in here
}
protected override void OnStop()
{
}
将安装程序文件添加到服务文件。
将帐户设置为本地服务
将起始类型设置为 automatic
构建项目一次,我的项目文件已部署到 C:\ Program Files(x86)\ Kofax \ CaptureSS \ ServLib \ Bin
在该目录中创建一个.bat文件并使用此内容
“ C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ installutil.exe”“ C:\ Program Files(x86)\ Kofax \ CaptureSS \ ServLib \ Bin \ DemoService.exe” 暂停
重新启动计算机(我这样做了...)
转到Windows服务面板并搜索您的服务。排雷设置为自动。启动服务。
启动它时,出现上述错误。那我想念什么吗?
如果相关,我可以在Windows 10上使用虚拟机。