Some Thread questions

D

**Developer**

I do the following:
Dim t As New Thread(AddressOf StartCancelThread)

t.Start()



What I'd like to do is to pass a string as a parameter to StartCancelThread.

Is that possible?



Also after t.Start I'd like to wait until the thread is running before I
procede.

How can I do that?





Thanks
 
K

kHSw

- Create a class and add parameters to the constructor (or via properties)

Public Class StartCancelThreadClass

Private _param1 As String

Public Sub New(ByVal param1 As String)

_param1 = param1

End Sub



Public Sub StartCancelThread()

System.Diagnostics.Debug.WriteLine(_param1)

End Sub

End Class



- Now you can create your thread (with parameter!) like this:



Dim sct As New StartCancelThreadClass("test")

Dim t As New Threading.Thread(AddressOf sct.StartCancelThread)

t.Start()


You could wait for your thread to end for instance like this:

While t.IsAlive

Application.DoEvents()

End While
 
D

**Developer**

Great
Thanks

kHSw said:
- Create a class and add parameters to the constructor (or via properties)

Public Class StartCancelThreadClass

Private _param1 As String

Public Sub New(ByVal param1 As String)

_param1 = param1

End Sub



Public Sub StartCancelThread()

System.Diagnostics.Debug.WriteLine(_param1)

End Sub

End Class



- Now you can create your thread (with parameter!) like this:



Dim sct As New StartCancelThreadClass("test")

Dim t As New Threading.Thread(AddressOf sct.StartCancelThread)

t.Start()


You could wait for your thread to end for instance like this:

While t.IsAlive

Application.DoEvents()

End While
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top