AsyncAwait 的基本用法
你可以并行启动一些缓慢的进程,然后在完成后收集结果:
Public Sub Main()
Dim results = Task.WhenAll(SlowCalculation, AnotherSlowCalculation).Result
For Each result In results
Console.WriteLine(result)
Next
End Sub
Async Function SlowCalculation() As Task(Of Integer)
Await Task.Delay(2000)
Return 40
End Function
Async Function AnotherSlowCalculation() As Task(Of Integer)
Await Task.Delay(2000)
Return 60
End Function
两秒钟后,两个结果都可用。