VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > vb >
  • vb.net 教程 6-10 传值给线程2

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
 
使用类传递多个值给线程:
 
Class clsStudent
    Public Name As String
    Public ID As Integer
End Class
    Sub sample5()
        Dim student As New clsStudent
        student.Name = "张三"
        student.ID = 1
 
        Dim sample5_Thread As New Thread(AddressOf sample5_PrintStudent)
        sample5_Thread.Start(student)
        sample5_Thread.Join()
        Console.WriteLine("End")
        Console.ReadKey()
    End Sub
    Sub sample5_PrintStudent(ByVal obj As Object)
        Dim testStudent As New clsStudent
        testStudent = CType(obj, clsStudent)
        Console.WriteLine("姓名:{0}  学号:{1}", testStudent.Name, testStudent.ID)
    End Sub
使用结构传递多个值给线程的例子:
 
    Structure strStudent
        Dim Name As String
        Dim ID As Integer
    End Structure
    Sub sample6()
        Dim student As strStudent
        student.Name = "张三"
        student.ID = 1
 
        Dim sample6_Thread As New Thread(AddressOf sample6_PrintStudent)
        sample6_Thread.Start(student)
        sample6_Thread.Join()
        Console.WriteLine("End")
        Console.ReadKey()
    End Sub
    Sub sample6_PrintStudent(ByVal obj As Object)
        Dim testStudent As strStudent
        testStudent = CType(obj, strStudent)
        Console.WriteLine("姓名:{0}  学号:{1}", testStudent.Name, testStudent.ID)
    End Sub
 
 
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
 
学习更多vb.net知识,请参看vb.net 教程 目录
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/UruseiBest/article/details/87893437

相关教程