How to do something on

2019-09-24 16:40发布

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?

1条回答
唯我独甜
2楼-- · 2019-09-24 17:01

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.

查看更多
登录 后发表回答