[英]Starting a service: “Error 1053: The service did not respond to the start or control request in a timely fashion”
I installed my c# application as windows service, by using the command installutil. 我使用命令installutil将c#应用程序安装为Windows服务。 It get successfully installed.
它已成功安装。 While starting the service I am getting the following error.
启动服务时,出现以下错误。
"Error 1053: The service did not respond to the start or control request in a timely fashion"
“错误1053:服务没有启动或控制请求及时”
Why it happens? 为什么会发生?
Below is the source code 下面是源代码
static void Main(string[] args)
{
// Get the version of the current application.
Assembly assem = Assembly.GetExecutingAssembly();
AssemblyName assemName = assem.GetName();
Version ver = assemName.Version;
// Console.WriteLine("{0}, Version {1}", assemName.Name, ver.ToString());
Console.WriteLine("{0} version {1}", assemName.Name, ver.ToString());
TouchService touchService = new TouchService();
if (Environment.UserInteractive)
{
bool show_help = false;
bool install_service = false;
bool uninstall_service = false;
string servicename = "";
OptionSet p = new OptionSet()
.Add("h|?|help", delegate(string v) { show_help = v != null; })
.Add("s|servicename=", "name of installed service", delegate(string v) { servicename = v; })
.Add("i|install", "install program as a Windows Service. A valid servicename is needed.", delegate(string v) { install_service = v != null; })
.Add("u|uninstall", "uninstall program from Windows Services. A valid servicename is needed.", delegate(string v) { uninstall_service = v != null; });
List<string> extra;
try
{
extra = p.Parse(args);
}
catch (OptionException e)
{
Console.Write("TouchServer: ");
Console.WriteLine(e.Message);
Console.WriteLine("Try `TouchServer --help' for more information.");
return;
}
if (show_help)
{
ShowHelp(p);
return;
}
else if (install_service)
{
IntegratedServiceInstaller Inst = new IntegratedServiceInstaller();
Inst.Install(servicename, null, "Provides XML data over HTTP for Touch clients",
System.ServiceProcess.ServiceAccount.NetworkService,
System.ServiceProcess.ServiceStartMode.Manual);
return;
}
else if (uninstall_service)
{
IntegratedServiceInstaller Inst = new IntegratedServiceInstaller();
Inst.Uninstall(servicename);
return;
}
// start and run the server,
// and receive commands from the console
else
{
touchService.OnStart(args);
while (true)
{
Console.Write("TouchServer>");
string commandLine = Console.ReadLine().ToLower();
if (commandLine == "exit" || commandLine == "x")
{
break;
}
if (commandLine == "quit" || commandLine == "q")
{
break;
}
else if (commandLine == "version" || commandLine == "v")
{
Console.WriteLine("{0} version {1}", assem.GetName().Name, assem.GetName().Version.ToString());
}
else if (commandLine == "list" || commandLine == "l")
{
TouchServer.showURLs = (TouchServer.showURLs == false) ? true : false;
Console.WriteLine("List URLs: {0}", (TouchServer.showURLs ? "active" : "inactive"));
}
else if (commandLine == "status" || commandLine == "s")
{
Console.WriteLine("{0,-20} {1,8}", "Name", "Sessions");
Console.WriteLine("----------------------------");
foreach (Site site in TouchServer.siteCollection.All)
{
Console.WriteLine("{0,-20} {1,8}", site.Name, site.AllSessions.Length);
}
Console.WriteLine();
}
}
touchService.OnStop();
}
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new TouchService()
};
ServiceBase.Run(ServicesToRun);
}
}
static void ShowHelp(OptionSet p)
{
Console.WriteLine("Usage: TouchServer [OPTIONS]+ ");
Console.WriteLine();
Console.WriteLine("Options:");
p.WriteOptionDescriptions(Console.Out);
Console.WriteLine();
Console.WriteLine("Providing no options results in the server running in console mode (for debugging purposes).");
}
public TouchService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
taskList.Clear();
taskList.Add(new TouchServerTask("TouchServer"));
taskList.Add(new HouseKeeperTask());
//TouchServer.Execute();
setupSynchronizerTasks();
taskList.StartAllTasks();
}
Your question has been answered here . 您的问题已在这里得到回答。
What's assumed is that there's a problem within your code that resides in 假设您的代码中存在一个问题
void OnStart(string[] args)
in your code. 在您的代码中。 In that case, attach a service debugger to troubleshoot your problem.
在这种情况下,请附加服务调试器以解决问题。
Good luck. 祝好运。
Your service does to much in OnStart
. 您的服务在
OnStart
中发挥了很大作用。
Start the service choose Tools->attach to process in Visual Studio, choose your service. 启动服务,选择“工具”->“附加以在Visual Studio中进行处理”,然后选择您的服务。 Break the process and try to figure out what the process is doing so long time in
OnStart
. 中断该过程,并尝试弄清楚
OnStart
该过程正在执行的时间很长。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.