VB.Net/Thread/Thread Status — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:45, 26 мая 2010

Get Thread status: start time, ID, Processor Time

Imports System.Threading
Public Class MainClass
   Shared Dim A As Thread = New Thread(AddressOf MethodA)
   Shared Dim B As Thread = New Thread(AddressOf MethodB)
   Shared Dim C As Thread = New Thread(AddressOf MethodC)
   Public Shared Sub Main()
        A.Name = "A"
        A.Start()
        B.Name = "B"
        B.Start()
        C.Name = "C"
        C.Start()

        Dim List As  System.Diagnostics.ProcessThreadCollection
        List =  System.Diagnostics.Process.GetCurrentProcess().Threads()
        Dim objThread As  System.Diagnostics.ProcessThread
        Console.WriteLine()
        For Each objThread In List
            Console.Write("Thread: {0:D5}", objThread.Id)
            Console.Write(" Start: {0}", objThread.StartTime)
            Console.WriteLine(" CPU Time: {0}", objThread.TotalProcessorTime)
            Console.Write(" State: {0}", objThread.ThreadState)
            If (objThread.ThreadState = System.Diagnostics.ThreadState.Wait) Then
                Console.Write("Reason: {0}", objThread.WaitReason())
            End If
            Console.WriteLine(" Address: {0}", objThread.StartAddress())
            Console.WriteLine()
        Next

   End Sub
   Shared Sub MethodA()
        Dim I As Integer
        B.Join()
        For I = 0 To 250
            System.Console.Write("A")
        Next
    End Sub
    Shared Sub MethodB()
        Dim I As Integer
        For I = 0 To 250
            System.Console.Write("B")
        Next
    End Sub
    Shared Sub MethodC()
        Dim I As Integer
        For I = 0 To 250
            System.Console.Write("C")
        Next
    End Sub
End Class