2012-08-28 79 views
-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"); 

     } 
+1

錯誤?例外? –

+0

它爲什麼不運行?它會給出錯誤嗎?什麼是'SharedData.APPLICATION_LOCAL_PATH'? –

+0

你可以發佈你的'開始'功能嗎? – Default

回答

0

您應該在您的OnStart函數中啓動一個新線程,否則ServiceManager會認爲應用程序已關閉。如果OnStart函數退出時速度較快,您還可以獲得此消息。

您可以看到提供的示例here如何啓動服務