Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Multithreaded Array
- Typically, when you want to assign names dynamically to objects, it's best to use a dictionary. In the dictionary, you would use the key for the dynamically assigned name and you would use the value as the object that is assigned that name. For instance:
- Dim d As New Dictionary(Of String, MyClass)()
- 'Add objects to dictionary
- d("dynamic name 1") = New MyClass()
- d("dynamic name 2") = New MyClass()
- 'Get object from dictionary by name
- Dim myObject As MyClass = d("dynamic name 1")
- The same method will work well with threads, for instance:
- Dim threads As New Dictionary(Of String, Thread)()
- Dim variableName = "Thread"
- For i As Integer = 0 To 5
- threads(variableName & "(" & i.ToString() & ")") = New Thread()
- Next
- However, if all you are doing is assigning numeric indexes to them, rather than string names, you could just use a list instead, like this:
- Dim threads As New List(Of Thread)()
- For i As Integer = 0 To 5
- threads.Add(New Thread())
- Next
- Then you could get the thread from the list by index like this:
- Dim t As Thread = threads(1)
- Or, if you have a set number of threads, you could easily use an array:
- Dim threads(4) As Thread
- For i As Integer = 0 To 5
- threads(i) = New Thread()
- Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement