Chinaunix首页 | 论坛 | 博客
  • 博客访问: 188558
  • 博文数量: 106
  • 博客积分: 3810
  • 博客等级: 中校
  • 技术积分: 1007
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-18 13:35
文章分类

全部博文(106)

文章存档

2014年(17)

2011年(5)

2010年(75)

2009年(9)

我的朋友

分类:

2010-04-27 08:06:44

Option Explicit On
Option Strict On

Imports System
Imports System.Threading

Public Class Test

    Shared Sub Main()
        Dim priorityTest As New PriorityTest()
        Dim threadOne As Thread = New Thread(AddressOf priorityTest.ThreadMethod)
        threadOne.Name = "ThreadOne"
        Dim threadTwo As Thread = New Thread(AddressOf priorityTest.ThreadMethod)
        threadTwo.Name = "ThreadTwo"
        threadOne.Priority = ThreadPriority.Highest
        threadTwo.Priority = ThreadPriority.Lowest

threadOne.Start()
        threadTwo.Start()
        Thread.Sleep(8000)
        priorityTest.LoopSwitch = False
        Console.ReadLine()
    End Sub

End Class

Public Class PriorityTest

    Dim loopSwitchValue As Boolean

    Sub New()
        loopSwitchValue = True
    End Sub

    WriteOnly Property LoopSwitch() As Boolean
        Set(ByVal value As Boolean)
            loopSwitchValue = Value
        End Set
    End Property

    Sub ThreadMethod()

        Dim threadCount As Long = 0
        While loopSwitchValue
            threadCount += 1
        End While

        Console.WriteLine("{0} with {1,11} priority " & _
            "has a count = {2,13}", Thread.CurrentThread.Name, _
            Thread.CurrentThread.Priority.ToString(), _
            threadCount.ToString("N0"))
    End Sub

End Class

'优先级别一共分以下5种 不指定默认为Normal

Highest

AboveNormal

Normal

BelowNormal

Lowest


阅读(252) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~