委托异步调用 VB

南楼画角 提交于 2020-01-24 01:56:05

Imports System.Delegate
Imports System.Threading
Delegate Function BinaryOp(ByVal arg1 As Integer, ByVal arg2 As Integer) As Integer


Module Module1
    Sub Main()
        Dim b As BinaryOp = AddressOf Add
        Dim IAR As IAsyncResult = b.BeginInvoke(10, 10, IAR, vbNull)
        While IAR.IsCompleted <> True
            Console.WriteLine("Main thread")
        End While

        Dim results As Integer = b.EndInvoke(IAR)
        Console.WriteLine(results)
        Console.Read()
    End Sub

    Public Function Add(ByVal arg1 As Integer, ByVal arg2 As Integer) As Integer
        Thread.Sleep(3000)

        Return arg1 + arg2
    End Function

End Module

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!