Chinaunix首页 | 论坛 | 博客
  • 博客访问: 845930
  • 博文数量: 756
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 4980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:40
文章分类

全部博文(756)

文章存档

2011年(1)

2008年(755)

我的朋友

分类:

2008-10-13 16:09:05

Imports System
Imports System.Threading

Class MyApp
  Shared Sub Main()

     '*** long-hand syntax for creating a thread
     Dim MyHandler As New ThreadStart(AddressOf TedsCode.MyAsyncTask)
     Dim ThreadA As New Thread(MyHandler)
     ThreadA.Start();

     '*** short-hand syntax for creating a thread
     Dim ThreadB As New Thread(AddressOf TedsCode.MyAsyncTask)
     ThreadB.Start()

  End Sub
End Class

Imports System
Imports System.Threading

Class MyApp
  Shared Sub Main()
    
    Dim ThreadA As New TedsThreadClass(1, "Bob")
    ThreadA.Start()

    Dim ThreadB As New TedsThreadClass(2, "Betty")
    ThreadB.Start()

  End Sub
End Class

Class TedsThreadClass
  
  '*** define custom fields and constructor with parameterized data
  Protected x As Integer
  Protected y As String
  Sub New(ByVal X as Integer, ByVal Y As String)
    Me.x = X
    Me.y = Y
  End Sub

  '*** instance method used to run asynchronous task
  Sub MyASyncTask()
    '*** this code has access to x and y
  End Sub
 
  '*** encapsulated threading support
  Protected InnerThread As New Thread(AddressOf Me.MyAsyncTask)
  Public Sub Start()
    InnerThread.Start()
  End Sub

End Class

--------------------next---------------------

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