关键词搜索

源码搜索 ×
×

vb.net 教程 6-10 传值给线程2

发布2021-09-11浏览350次

详情内容

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。

使用类传递多个值给线程:

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版权协议,转载请附上原文出处链接及本声明。

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载