Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Threading While Using ServiceControllerStatus.Stopped

Status
Not open for further replies.

arznrchrd

Technical User
May 17, 2006
234
US
I am using a separate thread that waits a certain amount of time before continuing while the main thread is kicking off a process and waiting for a service to stop. If the time elapses, I want the 2nd thread to gain access to the main thread's UI. Using delegates, etc work as long as the main thread is not in the serv.waitforstatus(servicecontroller.stopped) routine. Is there a way that the 2nd thread can tell the main thread to stop waiting for the service to stop and let the 2nd thread update the UI? When the 2nd thread gets to the part of updating the main UI, it doesn't until the main thread gets passed that service.controller.stopped. Example below:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As Threading.Thread
t = New Threading.Thread(AddressOf Me.ThreadTask)
t.Start()

Dim serv2 As New System.ServiceProcess.ServiceController("Service Name", "server name")
Dim servstat As String = serv2.Status.ToString()
serv2.WaitForStatus(ServiceControllerStatus.Stopped)

End Sub

Private Sub ThreadTask()
Thread.Sleep(10000)
Call AddTextToLabel("Done with timer")

End Sub

Private Delegate Sub AddTextToLabelDelegate(ByVal someText As String)
Private Sub AddTextToLabel(ByVal someText As String)
If Me.InvokeRequired Then
Dim delegate1 As New AddTextToLabelDelegate(AddressOf AddTextToLabel)
Dim parameters(0) As Object
parameters(0) = someText
Me.Invoke(delegate1, parameters)
Else
ReadingLog.Text = someText
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top