Как я могу отладить сервис, который не выключит ошибку 2189 - PullRequest
1 голос
/ 18 марта 2020

Я создал ряд Windows сервисов, использующих VB. NET. Они запускаются и бегают плавно. Они периодически просыпаются и проверяют таблицу в базе данных Oracle, делают некоторые вещи и go возвращаются в режим сна. Иногда служба зависает без регистрации, что является одной из проблем, которые мне нужно отладить.

Но первая проблема, которую я хочу устранить, это:

net stop "XXService"
The service could not be controlled in its present state.
More help is available by typing NET HELPMSG 2189.

Это произойдет, даже когда все работает гладко, а службы просыпаются и обрабатывают данные должным образом.

В настоящее время, когда служба просыпается, я пишу в файл журнала. Есть ли что-то, что я могу записать в файл журнала, чтобы помочь отладить это?

Кстати, чтобы остановить службу, я прекращаю процесс.

Редактировать:

На основе комментария ниже Я использовал неоднозначную терминологию. Чтобы уточнить Для сна я использую:

Friend WithEvents MainTimer As System.Timers.Timer

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer.  
' Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.MainTimer = New System.Timers.Timer
    CType(Me.MainTimer, System.ComponentModel.ISupportInitialize).BeginInit()
    '
    'MainTimer
    '
    Me.MainTimer.Enabled = False
    Me.MainTimer.Interval = intMainTimerInterval
    '
    'ALService
    '
    Me.ServiceName = "ALService"
    CType(Me.MainTimer, System.ComponentModel.ISupportInitialize).EndInit()

End Sub

В других местах я делаю;

Private Sub MainTimer_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles MainTimer.Elapsed
    Dim intCurrentHour As Integer = Date.Now.Hour
    MainTimer.Enabled = False
    If bolInitializationComplete = False _
    Then
        Logger(intDebug, "Waiting for initialization to complete.")
    Else
        If intCurrentHour < intStopHour And intCurrentHour >= intStartHour _
        Then
            Logger(intDebug, "Before checkAbslink")
            checkAbslink()
            intMainTimerInterval = intMainTimerInterval * 2
            If intMainTimerInterval > (intMaxSecondsToSleep * 1000) _
            Then
                intMainTimerInterval = (intMaxSecondsToSleep * 1000)
                intFileLogLevel = intTempFileLogLevel
            End If
            MainTimer.Interval = intMainTimerInterval
            Logger(intDebug, "After checkAbslink, sleeping " & CStr(intMainTimerInterval / 1000) & " seconds.")
        Else
            Logger(intInfo, "Waiting for Processing Hours")
            Logger(intInfo, "Current Hour=" & CStr(intCurrentHour) & " Start Hour=" & CStr(intStartHour) & " Stop Hour=" & CStr(intStopHour))
            intMainTimerInterval = (600 * 1000) ' 10 minutes
            MainTimer.Interval = intMainTimerInterval
        End If
    End If
    MainTimer.Enabled = True

End Sub

Редактировать:

В соответствии с запросом в комментарии здесь есть подпрограммы onStart и onStop;

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 strPath As String
    Dim intIndex As Integer
    strPath = Trim(System.Reflection.Assembly.GetExecutingAssembly().Location)
    intIndex = strPath.LastIndexOf("\") + 1
    strPath = strPath.Substring(0, intIndex)
    strRootPath = strPath
    getInitilizationParameters()
    Logger(intInfo, "Finished loading Initialization parameters")
    bolInitializationComplete = True
    MainTimer.Interval = 1000

End Sub

Protected Overrides Sub OnStop()
    bolStopping = True
    Logger(intInfo, "OnStop initialized")
    While bolProcessing
        RequestAdditionalTime(2000)
        Thread.Sleep(2000)
    End While
    bolProcessing = False
    ' Add code here to perform any tear-down necessary to stop your service.
End Sub

Я вижу потенциальную проблему в onStop, но я ожидаю "зависания" при остановке ситуации. Не ошибка 2189.

...