Working With ThreadsUse a class module for your threads code: Public Class Class1
'intThreadDevice is used to retrieve a parameter into the thread
Private intThreadDevice As Int32
'This is your threads main starting sub
Public Sub DoCheck() Dim intMyDeviceID As Int32 intMyDeviceID = intThreadDevice Do 'Do Some Thread Stuff CheckDeviceStatus(intMyDeviceID) System.Threading.Thread.Sleep(10000) Loop End Sub
'This property section is used to Get/Set intThreadDevice 'Use multiples of these if you have lots of vars to set
Property DeviceID() As Int32 Get Return intThreadDevice End Get Set(ByVal value As Int32) intThreadDevice = value End Set End Property
End Class
Calling your thread from the main program thread: 'Creating a usable copy of Class1 Dim cls1 As New Class1 'Inserting a value into your thread cls1.DeviceID = 12345
'Defining the thread proper with a reference to 'the main thread sub
Dim Thread1 As New System.Threading.Thread(AddressOf cls1.DoCheck)
'Starting the thread Thread1.Start()
'Ending the Thread 'Thread1.Abort()
|