How to do something on

2019-09-24 16:50发布

问题:

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

How exactly should I do that?

回答1:

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.