Does this work for you?

Module Module1

    Sub Main()
        Dim t1 As New MyThread()
        Dim t2 As New MyThread()

        t1.msg = "Hello from T1"

        t2.msg = "Hello from T2"

        Dim thr1 As New Threading.Thread(AddressOf t1.ThreadProc)
        Dim thr2 As New Threading.Thread(AddressOf t2.ThreadProc)

        thr1.Start()
        thr2.Start()

        Console.ReadLine()


    End Sub

End Module

Class MyThread
    Public msg As String

    Public Sub ThreadProc()
        Console.WriteLine(msg)
    End Sub
End Class

Regards

Richard
http://staff.develop.com/richardb

-----Original Message-----
From: dotnet discussion [mailto:[EMAIL PROTECTED]]On Behalf Of
Bryan Kelly
Sent: 02 May 2002 15:01
To: [EMAIL PROTECTED]
Subject: [DOTNET] Newbie Threading Question


As a VB.Net newbie (having only experience with VBScript), I'm struggling
to pass parameters to threads. Although the online help gives examples, I
can't get my head around the idea of delegates etc. While I've purchased a
book to help me get to grips with classes etc, I really need a solution to
this particular problem as soon as, and would be very grateful if someone
could take a few minutes to help.

The code below is from a console application. Instead of defining the
console output in the thread (in this case "Console Text"), I'd like to
pass a string to the thread so that multiple threads could output different
text.

Thanks in advance.
Bryan

THE CODE:
----------------------------------
Imports System
Imports System.Threading

Module Module1

    Sub Main()
        Dim MyThread As New Thread(AddressOf ThreadCode)
        MyThread.Start()

    End Sub

    Sub ThreadCode()
        Dim intLoopCounter As Integer
        For intLoopCounter = 1 To 1000
            Console.WriteLine("Console Text")
        Next
    End Sub

End Module

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to