Windows服务无法启动

问题描述 投票:0回答:1

服务中的整个代码是

 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.
        While 1 = 1
            Try
                Dim mLoop As New Init
            Catch ex As Exception

            End Try
        End While
    End Sub

在Init构造函数上我有代码

 Public Sub New()
        Dim rIni As New cIniFile

        Dim strPath As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
        strPath = New Uri(strPath).LocalPath
        rIni.Filename = strPath & "\Configuration.ini"
        rIni.LoadFromFile()

        ' TIME FOR Advertising 
        If (Format(Date.Now, "dddd") = "Monday" And rIni.ReadString("SMS_Advertise", "ADV_Mo", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
           (Format(Date.Now, "dddd") = "Tuesday" And rIni.ReadString("SMS_Advertise", "ADV_Tu", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
           (Format(Date.Now, "dddd") = "Wednesday" And rIni.ReadString("SMS_Advertise", "ADV_We", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
           (Format(Date.Now, "dddd") = "Thursday" And rIni.ReadString("SMS_Advertise", "ADV_Th", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
           (Format(Date.Now, "dddd") = "Friday" And rIni.ReadString("SMS_Advertise", "ADV_Fr", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
           (Format(Date.Now, "dddd") = "Saturday" And rIni.ReadString("SMS_Advertise", "ADV_Sa", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
           (Format(Date.Now, "dddd") = "Sunday" And rIni.ReadString("SMS_Advertise", "ADV_Su", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Advertise", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Then
            ProcessStart(strPath & "\tSMSAdvertise.exe")
        End If

        ' TIME FOR Notifications 
        If (Format(Date.Now, "dddd") = "Monday" And rIni.ReadString("SMS_Notification", "ADV_Mo", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
         (Format(Date.Now, "dddd") = "Tuesday" And rIni.ReadString("SMS_Notification", "ADV_Tu", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
         (Format(Date.Now, "dddd") = "Wednesday" And rIni.ReadString("SMS_Notification", "ADV_We", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
         (Format(Date.Now, "dddd") = "Thursday" And rIni.ReadString("SMS_Notification", "ADV_Th", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
         (Format(Date.Now, "dddd") = "Friday" And rIni.ReadString("SMS_Notification", "ADV_Fr", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
         (Format(Date.Now, "dddd") = "Saturday" And rIni.ReadString("SMS_Notification", "ADV_Sa", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Or
         (Format(Date.Now, "dddd") = "Sunday" And rIni.ReadString("SMS_Notification", "ADV_Su", 0) = 1 And Format(CDate(rIni.ReadString("SMS_Notification", "TimeSend")), "hh:mm") = Format(Now, "hh:mm")) Then
            ProcessStart(strPath & "\tSMSDate.exe")
        End If

    End Sub

    Private Sub ProcessStart(path As String)
        Dim proc As New Process
        proc = Process.Start(path)
        proc.WaitForExit()
    End Sub

但是,在安装该服务后,我有启动它的问题。我无法弄清楚它弹出的原因

服务没有及时响应启动或控制请求

在事件记录器中,我没有任何东西,而是在下面的图片上显示

Event logger

此外,我检查了主要子,它没有在调试模式

 Shared Sub Main()

        '#If DEBUG Then
        '        Dim servicio As New Service1
        '        servicio.OnStart(Nothing)
        '        System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite)
        '#Else
        Dim ServicesToRun() As System.ServiceProcess.ServiceBase
        ServicesToRun = New System.ServiceProcess.ServiceBase() {New Service1}
        System.ServiceProcess.ServiceBase.Run(ServicesToRun)
        '#End If

    End Sub

任何人都知道我错过了什么。

vb.net events service
1个回答
2
投票

如果您的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.
    dim T as new Thread(AddressOf MainWorker)
    T.Start()
End Sub

Private Sub MainWorker()
        While 1 = 1
        Try
            Dim mLoop As New Init
        Catch ex As Exception

        End Try
    End While
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.