Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Public Shared Async Function getMarketDetailFromAllExchangesAsync() As Task
    Dim taskList = New List(Of Task)
    For Each account In uniqueAccounts()
        Dim newtask = account.Value.getMarketInfoAsync()
        taskList.Add(newtask)

    Next
    Await Task.WhenAll(taskList.ToArray)

    Dim b = 1
End Function

The code work just fine.

However, I want to log every time a task is done

So I did

        newtask.ContinueWith(Async Function(x) LogEvents(account.ToString))

LogEvents is a normal function. I got 2 error

enter image description here

How exactly should I do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
258 views
Welcome To Ask or Share your Answers For Others

1 Answer

I did it this way

Public Shared Async Function getMarketDetailFromAllExchangesAsync() As Task
    Dim taskList = New List(Of Task)
    Dim starttime = jsonHelper.currentTimeStamp
    LogEvents("Start Getting Market Detail of All")
    For Each account In uniqueAccounts().Values
        Dim newtask = account.getMarketInfoAsync().ContinueWith(Sub() account.LogFinishTask("GetMarketDetail", starttime))
        taskList.Add(newtask)
        'newtask.ContinueWith(Sub() LogEvents(account.ToString))
    Next
    Await Task.WhenAll(taskList.ToArray)
    Dim b = 1
End Function

If anyone knows how to do so without a lambda that'll be great.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...