Threading

Skip all sorts of Safe Threading calls

Me.CheckForIllegalCrossThreadCalls = False  

Threading a Sub with Params!

Private Sub Btn_Click()

Dim evaluator As New Thread(Sub() Me.testthread(goodList, 1))

evaluator.Start()

Exit Sub


This is the testthread method:


Private Sub testthread(ByRef goodList As List(Of OneItem), ByVal coolvalue As Integer)

    StatusProgressBar.Maximum = 100000

    While (coolvalue < 100000)

        coolvalue = coolvalue + 1

        StatusProgressBar.Value = coolvalue

        lblPercent.Text = coolvalue & "%"

        Me.StatusProgressBar.Refresh()

    End While

End Sub

https://stackoverflow.com/questions/4018282/how-to-pass-multiple-parameters-in-thread-in-vb

System Timer (threading them)


'http://www.vbforums.com/showthread.php?469362-RESOLVED-2005-system-timers-timer-no-tag-property

Public Class myNewTimer

    Inherits System.Timers.Timer

    Private _IDNumber As String

    Property IDNumber() As String

        Get

            Return _IDNumber

        End Get

        Set(ByVal value As String)

            _IDNumber = value

        End Set

    End Property

End Class

    Sub StartTimer(sComputer As String)

        Dim oTimer As New myNewTimer

        'Dim oTimer As New System.Threading.Timer()

        AddHandler oTimer.Elapsed, AddressOf Timer_Tick

        oTimer.IDNumber = sComputer

        oTimer.Interval = 1000

        oTimer.Start()

        ' Do While Not bStop

        ' Application.DoEvents()

        '  Loop

    End Sub

  Sub StartAll()

        For Each sServer In {"server1","server2",…}

            Debug.Print(sServer)

            'Dim evaluator As New Threading.Thread(Sub() StartTimer(sServer))

            Dim evaluator As New Threading.Thread(Sub() StartTimer(sServer))

            evaluator.Start()

            iThreads += 1

            ' StartTimer("vs12app01")

            'StartTimer(".")

            ' StartTimer(sServer)

        Next

        While iThreads > 0 And Not bStop

            Application.DoEvents()

        End While

        bFirstRun = False

     

    End Sub

   Private Sub Timer_Tick(sender As Object, e As EventArgs)

        Dim instance As myNewTimer = DirectCast(sender, myNewTimer)

        instance.Stop()

        Debug.Print(Now & "  Tick for: " & instance.IDNumber.ToString)

   End Sub