ThreadStatic : ThreadStatic « 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 » ThreadStatic 
23.10.2.ThreadStatic
Imports System.Threading

public class Test
   Shared Dim obj As MyClass1 = new MyClass1
   public Shared Sub Main
               Dim thread1 As New Thread(AddressOf doSomething)
               Dim thread2 As New Thread(AddressOf doSomething)
               Dim thread3 As New Thread(AddressOf doSomething)
               thread1.Start()
               thread2.Start()
               thread3.Start()
   End Sub
   
   Private Shared Sub doSomething()
           Dim As Integer
           For i = To 3
               obj.SharedData = i
               obj.threadUniqueID = AppDomain.GetCurrentThreadId()
               Console.WriteLine("ID: " & obj.threadUniqueID & ", I:=" & i & ", SharedData: " & obj.SharedData.ToString())
               Thread.CurrentThread.Sleep(250)
           Next
   End Sub
End class

Public Class MyClass1
       <ThreadStatic()Public threadUniqueID As Integer
       Public SharedData As Integer = 0
End Class
ID: 2564, I:=1, SharedData: 1
ID: 3196, I:=1, SharedData: 1
ID: 2656, I:=1, SharedData: 1
ID: 2564, I:=2, SharedData: 2
ID: 3196, I:=2, SharedData: 2
ID: 2656, I:=2, SharedData: 2
ID: 2564, I:=3, SharedData: 3
ID: 3196, I:=3, SharedData: 3
ID: 2656, I:=3, SharedData: 3
23.10.ThreadStatic
23.10.1.ThreadStatic field
23.10.2.ThreadStatic
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.