-3

在我的 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");

      }
4

1 回答 1

0

您应该在您的OnStart函数中启动一个新线程,否则 ServiceManager 会认为应用程序已关闭。如果OnStart函数退出到快速,您也可以收到此消息。

您可以查看此处提供的示例以了解如何启动服务

于 2012-08-28T14:12:47.353 回答