[英]windows service project fails on a 1053 error when launching the service
I would like to create a Windows Service application with Visual Studio. 我想用Visual Studio创建一个Windows服务应用程序。 When launching the service I get this error:
启动服务时,我收到此错误:
error 1053 the service did not respond to the start or control request in a timely fashion
错误1053服务未及时响应启动或控制请求
So I removed my code and still run into this error. 所以我删除了我的代码,但仍然遇到此错误。 Maybe I missed some settings so this is my project to reproduce:
也许我错过了一些设置,所以这是我的重现项目:
First create the Windows Service App (C#) with Visual Studio 首先使用Visual Studio创建Windows服务应用程序(C#)
Set the architecture to x86. 将体系结构设置为x86。
Set the output path to another directory, mine is C:\\Program Files (x86)\\Kofax\\CaptureSS\\ServLib\\Bin . 将输出路径设置为另一个目录,我的是C:\\ Program Files(x86)\\ Kofax \\ CaptureSS \\ ServLib \\ Bin 。
Add the required dlls to the project, for example PDFSharp 将所需的dll添加到项目中,例如PDFSharp
Update Program.cs for debug mode ( RuntimeService is my service file) 更新Program.cs以获得调试模式( RuntimeService是我的服务文件)
private static void Main() { #if DEBUG new RuntimeService().RunDebugMode(); Thread.Sleep(TimeSpan.FromDays(1)); #else ServiceBase.Run(new RuntimeService()); #endif }
My RuntimeService.cs contains this code 我的RuntimeService.cs包含此代码
public RuntimeService() { InitializeComponent(); } public void RunDebugMode() { OnStart(null); } protected override void OnStart(string[] args) { // nothing in here } protected override void OnStop() { }
add an installer file to the service file. 将安装程序文件添加到服务文件中。
set the account to local service 将帐户设置为本地服务
set the starttype to automatic 将starttype设置为自动
build the project once, my project files got deployed to C:\\Program Files (x86)\\Kofax\\CaptureSS\\ServLib\\Bin 构建项目一次,我的项目文件部署到C:\\ Program Files(x86)\\ Kofax \\ CaptureSS \\ ServLib \\ Bin
create a .bat file in that directory and use this content 在该目录中创建一个.bat文件并使用此内容
"C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\installutil.exe" "C:\\Program Files (x86)\\Kofax\\CaptureSS\\ServLib\\Bin\\DemoService.exe" pause “C:\\ Windows \\ Microsoft.NET \\ Framework \\ v4.0.30319 \\ installutil.exe”“C:\\ Program Files(x86)\\ Kofax \\ CaptureSS \\ ServLib \\ Bin \\ DemoService.exe”暂停
restart your machine (I did this ...) 重启你的机器(我这样做了......)
head over to the Windows services panel and search for your service. 转到Windows服务面板并搜索您的服务。 Mine is set to automatic.
我的设置是自动的。 Launch the service.
启动该服务。
When launching it, I get the error mentioned above. 启动它时,我得到上面提到的错误。 So did I miss something?
所以我错过了什么?
If relevant, I use a Virtual Machine with Windows 10. 如果相关,我使用Windows 10的虚拟机。
I fixed the problem by switching from debug mode to release mode. 我通过从调试模式切换到释放模式来解决问题。 The answer comes from here
答案来自这里
https://stackoverflow.com/a/4305082/9945420 https://stackoverflow.com/a/4305082/9945420
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.