Passing Parameters
In many cases, you might need to pass data to new threads. You can do this by creating an instance of the ParameterizedThreadStart
delegate, which requires an argument of type Object
that you can use for sharing your data. The following code demonstrates how you create a thread with parameters:
Private Sub threadWithParameters(parameter As Object) Dim newThread As New Thread(New _ ParameterizedThreadStart(AddressOf _ executeThreadWithParameters)) newThread.Start(parameter)End Sub
Notice how the Thread.Start
method has an overload that takes the specified parameter as the data. Because such data is of type Object
, you need to convert ...
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.