C# 启动服务:";错误1053:服务未及时响应启动或控制请求”;
我使用installutil命令将c#应用程序安装为windows服务。 它已成功安装。在启动服务时,我遇到以下错误 “错误1053:服务未及时响应启动或控制请求” 为什么会这样 下面是源代码C# 启动服务:";错误1053:服务未及时响应启动或控制请求”;,c#,C#,我使用installutil命令将c#应用程序安装为windows服务。 它已成功安装。在启动服务时,我遇到以下错误 “错误1053:服务未及时响应启动或控制请求” 为什么会这样 下面是源代码 static void Main(string[] args) { // Get the version of the current application. Assembly assem = Assembly.GetExecutingAs
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();
}
static void Main(字符串[]args)
{
//获取当前应用程序的版本。
Assembly assem=Assembly.getExecutionGassembly();
AssemblyName assemName=assem.GetName();
版本版本=assemName.Version;
//WriteLine(“{0},版本{1}”,assemName.Name,ver.ToString());
WriteLine(“{0}版本{1}”,assemName.Name,ver.ToString());
TouchService TouchService=新的TouchService();
if(Environment.UserInteractive)
{
bool show_help=false;
bool install_service=false;
bool uninstall_service=false;
字符串servicename=“”;
OptionSet p=新OptionSet()
.Add(“h |?| help”,委托(字符串v){show_help=v!=null;})
.Add(“s | servicename=,“已安装服务的名称”,委托(字符串v){servicename=v;})
.Add(“i|install”,“将程序作为Windows服务安装。需要有效的服务名。”,委托(字符串v){install|Service=v!=null;})
.Add(“u|uninstall”,“从Windows服务卸载程序。需要有效的服务名。”,委托(字符串v){uninstall|u service=v!=null;});
额外列出;
尝试
{
额外=p.Parse(args);
}
捕获(OptionException e)
{
编写(“TouchServer:”);
控制台写入线(e.Message);
WriteLine(“有关更多信息,请尝试使用'TouchServer--help'”);
回来
}
如果(显示帮助)
{
ShowHelp(p);
回来
}
else if(安装_服务)
{
IntegratedServiceInstaller Inst=新的IntegratedServiceInstaller();
Inst.Install(servicename,null,“通过HTTP为触摸客户端提供XML数据”,
System.ServiceProcess.ServiceAccount.NetworkService,
系统.ServiceProcess.ServiceStartMode.Manual);
回来
}
else if(卸载\u服务)
{
IntegratedServiceInstaller Inst=新的IntegratedServiceInstaller();
Inst.Uninstall(servicename);
回来
}
//启动并运行服务器,
//并从控制台接收命令
其他的
{
touchService.OnStart(args);
while(true)
{
控制台。写入(“TouchServer>”;
string commandLine=Console.ReadLine().ToLower();
如果(命令行==“退出”| |命令行==“x”)
{
打破
}
如果(命令行==“退出”| |命令行==“q”)
{
打破
}
else if(命令行==“版本”| |命令行==“v”)
{
Console.WriteLine(“{0}version{1}”,assem.GetName().Name,assem.GetName().version.ToString());
}
else if(命令行==“list”| |命令行==“l”)
{
TouchServer.showURLs=(TouchServer.showURLs==假)?真:假;
WriteLine(“列表URL:{0}”,(TouchServer.showURL?“活动”:“非活动”);
}
else if(命令行==“状态”| |命令行==“s”)
{
WriteLine(“{0,-20}{1,8}”,“Name”,“Sessions”);
Console.WriteLine(“-------------------------------”;
foreach(TouchServer.siteCollection.All中的站点)
{
WriteLine({0,-20}{1,8}),site.Name,site.AllSessions.Length);
}
Console.WriteLine();
}
}
touchService.OnStop();
}
}
其他的
{
ServiceBase[]ServicesToRun;
ServicesToRun=新的ServiceBase[]
{
新TouchService()
};
ServiceBase.Run(ServicesToRun);
}
}
静态无效显示帮助(Optip)
{
WriteLine(“用法:TouchServer[OPTIONS]+”;
Console.WriteLine();
Console.WriteLine(“选项:”);
p、 WriteOptions描述(Console.Out);
Console.WriteLine();
WriteLine(“不提供任何选项会导致服务器在控制台模式下运行(用于调试)。”;
}
公共TouchService()
{
初始化组件();
}
启动时受保护的覆盖无效(字符串[]args)
{
taskList.Clear();
任务列表。添加(新的TouchServer任务(
void OnStart(string[] args)