How to do something on

回眸只為那壹抹淺笑 提交于 2020-01-17 15:49:11

问题


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.



来源:https://stackoverflow.com/questions/55883154/how-to-do-something-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!