I'm simply trying to keep a log list for my application events.
I'm trying to send text to the log from a seperate thread with the following code:

Imports System.Threading

Public Class Main

Private worker1 As Thread

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        worker1 = New Thread(AddressOf test)
        worker1.Start()
        log(logconsole, "Ready")
        test()
    End Sub

    Private Delegate Sub AppendTextBoxDelegate(ByVal TB As TextBox, ByVal txt As String)

    Private Sub log(ByVal TB As TextBox, ByVal txt As String)
        If TB.InvokeRequired Then
            TB.Invoke(New AppendTextBoxDelegate(AddressOf log), New Object() {TB, txt})
        Else
            TB.AppendText(txt)
        End If
    End Sub

    Sub test()
        log(logconsole, "text")
    End Sub
End Class

this almost works except it prints the test() output twice...

I only need it printed once.

It's printing twice because you're calling it twice..

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        worker1 = New Thread(AddressOf test)
        ' Logging "test" for first time
        worker1.Start() 
        ' Logging "Ready"
        log(logconsole, "Ready")
        'Logging "test" for second time
        test() 
    End Sub
commented: thanks! I thought it had to be something silly like that! +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.