-----Original Message-----
Hi Michael,
Your runnable class is pretty much what I guessed.
Here's a class (at end) similar to what Mike gave but it uses Delegates
rather than creating Threads directly. (though I've called the Delegate
variable CameraThread). Delegates can be called asynchronously in hich case
they grab a Thread from the ThreadPool. This is recommended practice where
you'll be using a number of Threads.
The class also uses a ListBox to show feedback and demonstrates the safe
GUI access that Stephen was talking about.
ListBox.BeginInvoke
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/cpref/html/fr
lrfsystemwindowsformscontrolclassbegininvoketopic2.asp
Delegates Tutorial (not as helpful as it could be)
http://msdn.microsoft.com/library/default.asp? url=/library/en-
us/cpguide/html/cpovrasynchronousdelegates.asp
Regards,
Fergus
<code>
Public Module RunnableCameras
Public lstCameras As ListBox
Public Sub LetsHaveSomeCameras
Dim aoCameras(5) As Camera
Dim N As Integer
For N = 0 To 4
aoCameras(N) = New Camera ("Camera " & N + 1)
aoCameras(N).Start ("Hi from " & N + 1)
Threading.Thread.Sleep (150) 'Stagger them for fun.
Next
End Sub
Public Class Camera
Delegate Sub CameraThread (sFoo As String)
Delegate Sub FeedbackCallBack (sText As String)
Private oThread As New CameraThread (AddressOf GoCameraGo)
Private sName As String
'This will execute in the caller's thread.
Public Sub New (sThisName As String)
sName = sThisName & " "
End Sub
'This will execute in the caller's thread.
Public Sub Start (sFoo As String)
oThread.BeginInvoke (sFoo, Nothing, Nothing)
End Sub
'This will execute in its own (ThreadPool) thread.
Public Sub GoCameraGo (sFoo As String)
Dim GiveFeedback As New FeedbackCallBack (AddressOf AddToList)
Dim I As Integer
For I = 1 To 50
Dim sBar As String = sName & "[" & I & "]: " & sFoo
'Tell lstCameras via Message Queue to "Come get some!!"
lstCameras.BeginInvoke (GiveFeedback, New Object() {sBar})
Threading.Thread.Sleep (30)
Next
End Sub
'This will execute in the ListBox's thread.
Private Sub AddToList (sText As String)
lstCameras.Items.Add (sText)
lstCameras.SelectedIndex = lstCameras.Items.Count - 1
End Sub
End Class
End Module
Private Sub DoTest
lstCameras = Me.ListBox1
LetsHaveSomeCameras
End Sub
</code>
.