【发布时间】:2018-03-08 00:50:38
【问题描述】:
不明白为什么我的 Windows 服务只能在调试模式下工作。
只使用了三个函数。
<System.Diagnostics.DebuggerNonUserCode()>
Shared Sub Main()
'Dim servicio As New Service1
'servicio.OnStart(Nothing)
'System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite)
WriteLog("Starting it")
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
ServicesToRun = New System.ServiceProcess.ServiceBase() {New Service1}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End Sub
Public Sub MainWorker()
While 1 = 1
Try
Dim mLoop As New Init
Catch ex As Exception
End Try
End While
End Sub
虽然它处于调试模式,但它作为方法 OnStart 的魅力。
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Try
Dim T As New Thread(AddressOf MainWorker)
T.Start()
Catch ex As Exception
End Try
End Sub
但是当它在没有调试的情况下使用(安装并运行)时,它不会弹出任何错误消息。状态正在运行。但什么也没有发生。甚至没有日志消息“正在启动”...
编辑:pastebin 上的初始化类PASTEBIN.INIT
【问题讨论】:
-
它可能不会弹出错误消息,因为您正在吞噬您的异常。尝试在你的 catch 块中加入某种日志记录。
-
@tgolisch 我把记录器放回去了。似乎服务根本没有运行这个初始化,甚至没有继续 OnStart 方法:S
-
检查您的 Windows 事件日志。他们是否在您的服务启动时捕获任何错误?
-
@tgolisch 没有捕获任何错误