J
juky
Hi all,
I have a loop in the thread checking for a particular service status,
whenever the status changes to "stopped" a RaiseEvent is generated by
thread and another function runs. At the same time the thread is
suspended. When I try to resume it from the another function I have
some problems.
Thank you.
Juky
Here the code:
Public Event StatusEventRaise(ByVal EventGenerated As Integer)
Dim StatusService As Threading.Thread
Private svc As ServiceController
.......
Public Sub New()
.....
AddHandler StatusEventRaise, AddressOf StatusEventRaiseHandler
StatusService = New Threading.Thread(AddressOf LoopCheck)
StatusService.Start()
....
end Sub
Private Sub LoopCheck()
While True
svc.Refresh()
Select Case svc.Status
Case ServiceControllerStatus.StopPending
RaiseEvent StatusEventRaise
ServiceControllerStatus.StopPending)
StatusService.Suspend()
Case ServiceControllerStatus.Stopped
RaiseEvent
StatusEventRaise(ServiceControllerStatus.Stopped)
Me.StatusService.Suspend()
End Select
End While
End Sub
Private Sub StatusEventRaiseHandler(ByVal EventGenerated As Integer)
Static nr As Integer = 0
Select Case EventGenerated
Case ServiceControllerStatus.Stopped
svc.Start()
StatusService.Resume()
Case ServiceControllerStatus.StopPending
While svc.Status <> ServiceControllerStatus.Stopped
svc.Refresh()
End While
svc.Start()
while svc.Status <> ServiceControllerStatus.Running
svc.Refresh()
End While
StatusService.Resume()
End Select
End Sub
I have a loop in the thread checking for a particular service status,
whenever the status changes to "stopped" a RaiseEvent is generated by
thread and another function runs. At the same time the thread is
suspended. When I try to resume it from the another function I have
some problems.
Thank you.
Juky
Here the code:
Public Event StatusEventRaise(ByVal EventGenerated As Integer)
Dim StatusService As Threading.Thread
Private svc As ServiceController
.......
Public Sub New()
.....
AddHandler StatusEventRaise, AddressOf StatusEventRaiseHandler
StatusService = New Threading.Thread(AddressOf LoopCheck)
StatusService.Start()
....
end Sub
Private Sub LoopCheck()
While True
svc.Refresh()
Select Case svc.Status
Case ServiceControllerStatus.StopPending
RaiseEvent StatusEventRaise
ServiceControllerStatus.StopPending)
StatusService.Suspend()
Case ServiceControllerStatus.Stopped
RaiseEvent
StatusEventRaise(ServiceControllerStatus.Stopped)
Me.StatusService.Suspend()
End Select
End While
End Sub
Private Sub StatusEventRaiseHandler(ByVal EventGenerated As Integer)
Static nr As Integer = 0
Select Case EventGenerated
Case ServiceControllerStatus.Stopped
svc.Start()
StatusService.Resume()
Case ServiceControllerStatus.StopPending
While svc.Status <> ServiceControllerStatus.Stopped
svc.Refresh()
End While
svc.Start()
while svc.Status <> ServiceControllerStatus.Running
svc.Refresh()
End While
StatusService.Resume()
End Select
End Sub