[英]Can't start service, error 1053, made in Visual Studio, c#
So i've made a small service program, but it won't start.所以我做了一个小服务程序,但它不会启动。 It installs by itself, but I don't have it in auto-start.
它自己安装,但我没有在自动启动中安装它。 It's on a windows 7, 64 bit system.
它在 Windows 7、64 位系统上。
When I find it in Services, right click the service and have it start, it times out with the error 1053 after about 30 seconds.当我在服务中找到它时,右键单击该服务并启动它,它在大约 30 秒后超时并显示错误 1053。
I am running the program as release, and not debug.我将程序作为发行版运行,而不是调试。 Tried to install as local admin and do everything as local admin.
尝试以本地管理员身份安装并以本地管理员身份执行所有操作。 The OnStart() and OnStop() methods are empty with no code, I removed it all to eliminate what it could be.
OnStart() 和 OnStop() 方法是空的,没有代码,我将它们全部删除以消除它可能是什么。 Tried putting a small logging action that I know works(I use it to create a log file when the install is successful) at the start of OnStart() but it never reaches it.
尝试在 OnStart() 开始时放置一个我知道有效的小型日志记录操作(我在安装成功时使用它来创建日志文件),但它从未到达它。
Help?帮助?
Edit:编辑:
Here is my Program.cs code:这是我的 Program.cs 代码:
namespace TestService
{
static class Program
{
// The main entry point for the application.
static void Main()
{
//Install self
SelfInstaller.InstallMe();
}
}
}
Here is my Library.cs:这是我的 Library.cs:
namespace TestService
{
//Library to store public methods
public static class Library
{
//Method to write to a logfile
public static void WriteLogFile(string Message)
{
StreamWriter sw = null;
try
{
sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\Logfile.txt", true);
sw.WriteLine(DateTime.Now.ToString() + ": " + Message.ToString());
sw.Flush();
sw.Close();
}
catch
{
//empty
}
}
}
}
Here is my Service1.cs:这是我的 Service1.cs:
namespace TestService
{
public partial class Service1 : ServiceBase
{
//Initialize
public Service1()
{
InitializeComponent();
}
//On service start
protected override void OnStart(string[] args)
{
}
//On service stop
protected override void OnStop()
{
}
}
}
It seems like you found a tutorial but followed only half of it.您似乎找到了一个教程,但只遵循了其中的一半。
Your current main()
code will install the service every time you try to start it:您当前的
main()
代码将在您每次尝试启动服务时安装该服务:
static void Main()
{
//Install self
SelfInstaller.InstallMe();
}
So that won't let the ServiceManager know the service has been started - as it isn't.所以这不会让 ServiceManager 知道服务已经启动 - 因为它不是。
You need to decide, in main()
, whether you want to start, install, uninstall or debug the service.您需要在
main()
决定是否要启动、安装、卸载或调试服务。 It's common to do so using command-line arguments, where no arguments supplied means "start the service".使用命令行参数这样做是很常见的,其中不提供参数意味着“启动服务”。
How to do this is also shown in that very tutorial.那个教程中也展示了如何做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.