AnonGod
IS-IT--Management
- Jun 5, 2000
- 223
This app restarts services on a server. Everything is working well except the sub that runs when the custom event is fired is running multiple times. Example - first time btnTest is clicked, the event code runs once. Second time the btnTest is clicked, the event code runs twice, and so on.
Thought I might have missed something in the event handling like clearing a buffer or queue, I don't know. Any help is appreciated. Thanks!
-Andrew
[Signature modified by admin request]
-TAG
anongod@hotmail.com
'Drawing on my fine command of language, I said nothing.'
Thought I might have missed something in the event handling like clearing a buffer or queue, I don't know. Any help is appreciated. Thanks!
Code:
Public Class Services_Class
' Public Events
Public Event RestartComplete(ByVal success As Boolean)
Public Sub RestartServices()
MsgBox(location)
If MsgBox("Are you sure?", MsgBoxStyle.YesNo, "Confirm") <> MsgBoxResult.Yes Then
RaiseEvent RestartComplete(False)
Exit Sub
End If
ErrorMsg("Test Error Message")
RaiseEvent RestartComplete(True)
Exit Sub
End Sub
End Class
' Form Code:
Dim cServices As New Services_Class
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
' Restart
btnTest.Enabled = False
Dim thread1 As New Threading.Thread(AddressOf cServices.RestartServices)
AddHandler cServices.RestartComplete, AddressOf RestartCompleteEventHandler
StatusBar2.Panels(0).Text = "Please wait... restarting services..."
thread1.Start()
End Sub
Private Sub RestartCompleteEventHandler(ByVal success As Boolean)
MsgBox("RestartComplete: " & success.ToString)
If success Then
StatusBar2.Panels(0).Text = "Services successfully restarted."
MsgBox("Services restarted.")
Else
StatusBar2.Panels(0).Text = "There was an error restarting services."
End If
btnTest.Enabled = True
End Sub

[Signature modified by admin request]
-TAG
anongod@hotmail.com
'Drawing on my fine command of language, I said nothing.'