当前位置:网站首页>[ VB.NET Tips] four methods of thread passing parameters

[ VB.NET Tips] four methods of thread passing parameters

2020-11-10 15:13:34 Irving the procedural ape

Thread Thread start method , Generally speaking, it's either a parameterless method , Or one with object Parameter method and in Start Pass the value of the parameter when .
But we can use some techniques to pass unlimited parameters to methods . These methods can be integrated in the actual use process .
The method is simple, directly on the code , For your reference .

Imports System.ThreadingModule Module1 Sub Main()  ' The first one is : stay Start Pass the parameter value in , But the parameter type in the method needs to be object type   Dim t1 As New Thread(AddressOf CountNumber)  t1.Start(10)  ' The second kind : adopt Lambda Expression creation thread , You can pass any parameter   Dim t2 As New Thread(Sub()         PrintNumber(20)        End Sub)  t2.Start()  ' The third kind of : Passing parameters by instantiating classes , Then call the class method   Dim c As New Count(10)  Dim t3 As New Thread(AddressOf c.CountNumber)  t3.Start()  ' A fourth : By passing a class or structure , To pass multiple parameters to the method   Dim p As New Person() With {   .FirstName = " yan ",   .LastName = " Chasan "   }  Dim t4 As New Thread(AddressOf ShowName)  t4.Start(p)  Console.Read() End Sub ' Passing a single parameter  Private Sub CountNumber(number As Object)  Dim sum As.........

版权声明
本文为[Irving the procedural ape]所创,转载请带上原文链接,感谢