KB̉𓚁B3VB.NETŁiVB03.vbj

Imports System
Imports System.Threading
Imports KYLib

Public Class Staff
    Dim Name As String
    Dim Count As Int16

    Public Sub New(ByVal Name As String)
        Me.Name = Name
        Count = 0
    End Sub

    Public Sub Work()
        While Count < 100
            Count = Count + 1
            Console.WriteLine("{0} is working: {1}", Name, Count)
            Thread.Sleep(200)
        End While
    End Sub
End Class

Module Module1

    Sub Main()
        Const Nmax As Integer = 1000
        Dim MyStaff(Nmax) As Staff
        Dim MyThread(Nmax) As Thread

        Dim n As Integer

        For n = 0 To Nmax - 1
            Dim name As String = Printf.i("Staff%04d", n)
            Console.WriteLine("Creating " + name)
            MyStaff(n) = New Staff(name)
            MyThread(n) = New Thread(New ThreadStart(AddressOf MyStaff(n).Work))
            MyThread(n).Start()
            Thread.Sleep(100)
        Next

    End Sub

End Module