Use the QueueUserWorkItem method to queue a task and supply the data for the task. : ThreadPool « Thread « VB.Net Tutorial






Imports System
Imports System.Threading

Public Class MyData
    Public MyStringValue As String
    Public Value As Integer
    Public Sub New(text As String, number As Integer)
        MyStringValue = text
        Value = number
    End Sub
End Class

Public Class Example
    Public Shared Sub Main()
        Dim ti As New MyData("value", 42)
        If ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ThreadProc), ti) Then
            Thread.Sleep(1000)
        Else
            Console.WriteLine("Unable to queue ThreadPool request.")
        End If
    End Sub
    Shared Sub ThreadProc(stateInfo As Object)
        Dim ti As MyData = CType(stateInfo, MyData)
        Console.WriteLine(ti.MyStringValue, ti.Value)
    End Sub
End Class








23.9.ThreadPool
23.9.1.Thread Pool
23.9.2.Get Available Threads in a ThreadPool and Get Max Threads in a ThreadPool
23.9.3.Queue a simple task, represented by the ThreadProc method, using the QueueUserWorkItem method.
23.9.4.Use the QueueUserWorkItem method to queue a task and supply the data for the task.