Весь обслуживаемый код

 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

Кто-нибудь знает, что мне не хватает.

0
programer Anel 1 Мар 2018 в 18:39

1 ответ

Лучший ответ

Если у вас есть время true в вашем 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
2
Sasha 1 Мар 2018 в 19:22