在我的Windows服务中我创建要记录的文件,但现在服务无法运行
Logger.InitLogFile("BridgeServiceLog.txt");
给我这个错误错误1053:服务没有及时响应启动或控制请求
public BridgeService()
{
InitializeComponent();
Logger.InitLogFile("BridgeServiceLog.txt");
Trace.WriteLine(Logger.logSwitch.TraceInfo, "Trace Started");
this.ServiceName = "BridgeService";
if (!System.Diagnostics.EventLog.SourceExists("BridgeSource"))
{
System.Diagnostics.EventLog.CreateEventSource("BridgeSource", "BridgeLog");
}
_bridgeServiceEventLog.Source = "BridgeSource";
_bridgeServiceEventLog.Log = "BridgeLog";
}
我的onStart方法
protected override void OnStart(string[] args)
{
Trace.WriteLineIf(Logger.logSwitch.TraceInfo, "OnStart method Started");
try
{
_bridgeServiceEventLog.WriteEntry("new OnStart");
if (Vytru.Platform.Bridge.Configuration.LicenseValidetor.ValidCountAndTypeDevices())
{
SharedData.InitializeBridge();
// WsInitializeBridge();
}
else
{
this.Stop();
_bridgeServiceEventLog.WriteEntry("LicenseValidetor Error");
}
_bridgeServiceEventLog.WriteEntry("end Start");
}
catch (Exception e)
{
Trace.WriteLineIf(Logger.logSwitch.TraceError, e.Message);
_bridgeServiceEventLog.WriteEntry("error In onstart method " + e.Message);
}
Trace.WriteLineIf(Logger.logSwitch.TraceInfo, "OnStart Ended");
}
答案 0 :(得分:0)
您应该在OnStart
函数中启动一个新线程,否则ServiceManager会认为应用程序已关闭..如果OnStart
函数退出为快,您也可以收到此消息。
您可以看到提供here的示例,了解如何启动服务