Get Available Threads in a ThreadPool and Get Max Threads in a ThreadPool : ThreadPool « Thread « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Thread » ThreadPool 
23.9.2.Get Available Threads in a ThreadPool and Get Max Threads in a ThreadPool
Imports System.Threading

public class Test
   public Shared Sub Main
               Dim msg As String : Dim As Integer

               Dim job As New MyJob()

               For i = To 5
                       ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf job.MyTask), i)
               Next
               Thread.Sleep(2000)
   End Sub
End class


Public Class MyJob
       Private Msg As String
       Dim availWorker As Integer = Dim maxWorker As Integer = 0
       Dim availCPT As Integer = Dim maxCPT As Integer = 0
       
       Public Sub MyTask(ByVal ThreadStateData As Object)
               Console.WriteLine("Performing Task. Data Passed: " & ThreadStateData)
               ThreadPool.GetAvailableThreads(availWorker, availCPT)
               ThreadPool.GetMaxThreads(maxWorker, maxCPT)
               Console.WriteLine("--Available Worker Threads: " & availWorker.ToString())
               Console.WriteLine("--Maximum Worker Threads: " & maxWorker.ToString())
               Console.WriteLine("--Available Completion Port Threads: " & availCPT.ToString())
               Console.WriteLine("--Maximum Completion Port Threads: " & maxCPT)
       End Sub
End Class
Performing Task. Data Passed: 1
--Available Worker Threads: 24
--Maximum Worker Threads: 25
--Available Completion Port Threads: 1000
--Maximum Completion Port Threads: 1000
Performing Task. Data Passed: 2
--Available Worker Threads: 24
--Maximum Worker Threads: 25
--Available Completion Port Threads: 1000
--Maximum Completion Port Threads: 1000
Performing Task. Data Passed: 3
--Available Worker Threads: 24
--Maximum Worker Threads: 25
--Available Completion Port Threads: 1000
--Maximum Completion Port Threads: 1000
Performing Task. Data Passed: 4
--Available Worker Threads: 24
--Maximum Worker Threads: 25
--Available Completion Port Threads: 1000
--Maximum Completion Port Threads: 1000
Performing Task. Data Passed: 5
--Available Worker Threads: 24
--Maximum Worker Threads: 25
--Available Completion Port Threads: 1000
--Maximum Completion Port Threads: 1000
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.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.