vb.net线程返回值 vbnet多线程编程

vb.net多线程如何返回参数,举个例子,谢谢Public Class Form1
Public Class SquareClass '把多线程调用的函数封装到类中,通过类事件返回
Public Value As Double
Public Square As Double
Public Event ThreadComplete(ByVal Square As Double)
Public Sub CalcSquare()
Square = Value * Value
RaiseEvent ThreadComplete(Square)
End Sub
End Class
Dim WithEvents oSquare As SquareClass
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click '多线程返回值测试,当线程运行完成激发事件
oSquare = New SquareClass()
Dim t As New Threading.Thread(AddressOf oSquare.CalcSquare)
oSquare.Value = https://www.04ip.com/post/30
t.Start()
End Sub
Sub SquareEventHandler(ByVal Square As Double) Handles oSquare.ThreadComplete '响应事件函数
MsgBox("The square is "Square)
End Sub
End Class
vb.net怎么使用函数返回值 。。。比如function a() As String 返回一个值 , 在function b()里怎么使用1、vb.net线程返回值我有一个functionvb.net线程返回值,如下vb.net线程返回值:
function b()
'...
return "abc"
end function
2、调用时vb.net线程返回值,这样子用vb.net线程返回值:
Response.write(b());
3、运行结果:
abc
VB.NET 在线程如何返回Function的值?Thread不会返回值的 。你应该创建委托的 , 使用委托的异步方法
Dim funcInt32 As Func(Of String, Integer) = AddressOf GetList
Dim s As IAsyncResult = funcInt32.BeginInvoke("(参数)", Nothing, Nothing)
’在要获得结果的地方调用EndInvoke方法结束异步调用并获得结果 。
Dim result As Int32 = funcInt32.EndInvoke(s)
【vb.net线程返回值 vbnet多线程编程】关于vb.net线程返回值和vbnet多线程编程的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读