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 StatusEventRais e(ByVal EventGenerated As Integer)
Dim StatusService As Threading.Threa d
Private svc As ServiceControll er
.......
Public Sub New()
.....
AddHandler StatusEventRais e, AddressOf StatusEventRais eHandler
StatusService = New Threading.Threa d(AddressOf LoopCheck)
StatusService.S tart()
....
end Sub
Private Sub LoopCheck()
While True
svc.Refresh()
Select Case svc.Status
Case ServiceControll erStatus.StopPe nding
RaiseEvent StatusEventRais e
ServiceControll erStatus.StopPe nding)
StatusService.S uspend()
Case ServiceControll erStatus.Stoppe d
RaiseEvent
StatusEventRais e(ServiceContro llerStatus.Stop ped)
Me.StatusServic e.Suspend()
End Select
End While
End Sub
Private Sub StatusEventRais eHandler(ByVal EventGenerated As Integer)
Static nr As Integer = 0
Select Case EventGenerated
Case ServiceControll erStatus.Stoppe d
svc.Start()
StatusService.R esume()
Case ServiceControll erStatus.StopPe nding
While svc.Status <> ServiceControll erStatus.Stoppe d
svc.Refresh()
End While
svc.Start()
while svc.Status <> ServiceControll erStatus.Runnin g
svc.Refresh()
End While
StatusService.R esume()
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 StatusEventRais e(ByVal EventGenerated As Integer)
Dim StatusService As Threading.Threa d
Private svc As ServiceControll er
.......
Public Sub New()
.....
AddHandler StatusEventRais e, AddressOf StatusEventRais eHandler
StatusService = New Threading.Threa d(AddressOf LoopCheck)
StatusService.S tart()
....
end Sub
Private Sub LoopCheck()
While True
svc.Refresh()
Select Case svc.Status
Case ServiceControll erStatus.StopPe nding
RaiseEvent StatusEventRais e
ServiceControll erStatus.StopPe nding)
StatusService.S uspend()
Case ServiceControll erStatus.Stoppe d
RaiseEvent
StatusEventRais e(ServiceContro llerStatus.Stop ped)
Me.StatusServic e.Suspend()
End Select
End While
End Sub
Private Sub StatusEventRais eHandler(ByVal EventGenerated As Integer)
Static nr As Integer = 0
Select Case EventGenerated
Case ServiceControll erStatus.Stoppe d
svc.Start()
StatusService.R esume()
Case ServiceControll erStatus.StopPe nding
While svc.Status <> ServiceControll erStatus.Stoppe d
svc.Refresh()
End While
svc.Start()
while svc.Status <> ServiceControll erStatus.Runnin g
svc.Refresh()
End While
StatusService.R esume()
End Select
End Sub
Comment