Click here to Skip to main content
15,886,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
 Dim taskList = New List(Of Task)()

 For Each pair As KeyValuePair(Of String, String) In pairs
 taskList.Add(Task.Factory.StartNew(
 Sub() 
 geXml.Execute()//which returns List(Of String) 
 End Sub
 Next
In this case how can I implement Async Wait call, because I have to use this List(Of String) becasue it is getting data from storage procedure.


What I have tried:

For Each pair As KeyValuePair(Of String, String) In pairs
taskList.Add(Task.Factory.StartNew(
Sub()
geXml.Execute()//which returns List(Of String)
End Sub
Next
Posted
Updated 24-Aug-16 4:12am

1 solution

Assuming you want to await the taskList and get the results, something like this should work:
VB.NET
Dim taskList As New List(Of Task(Of List(Of String)))()

For Each pair As KeyValuePair(Of String, String) In pairs
    taskList.Add(Task.Run(Function() geXml.Execute()))
Next

Dim results As IList(Of IList(Of String)) = Await Task.WhenAll(taskList)
 
Share this answer
 
Comments
Member 11491784 24-Aug-16 10:58am    
Hi I am unable to use because its saying that run is not memebr of System.Threading.Tasks
taskList.Add(Task.Run( instead of this I am using this
Task.Factory.StartNew(Function()

And also Await Task.WhenAll(taskList) is not available

Can i use somthing liek this Dim results As IList(Of IList(Of String)) = Await Task.WaitAll(taskList)
Richard Deeming 24-Aug-16 11:00am    
Then you're not using .NET 4.5?

Which version of Visual Studio are you using?
Richard Deeming 24-Aug-16 12:56pm    
If you're not using Visual Studio 2015, then you can't use Async / Await.

If you're using Visual Studio 2015, but targeting .NET 4.0, you'll need to add the Microsoft.Bcl.Async[^] NuGet package. Some methods such as Task.Run will belong to a class called TaskEx instead. You'll also need to make sure your users have KB2468871[^] installed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900