Results 1 to 2 of 2

Thread: Can we use continuewith to follow a task with another task?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2019
    Posts
    9

    Can we use continuewith to follow a task with another task?

    0

    Code:
        For Each account In _accounts11
            Dim newtask = account.readbalancesAsync()
            newtask = newtask.ContinueWith(Sub() account.LogFinishTask("Getting Balances", starttime))
            newtask = newtask.ContinueWith(Async Function() account.getOrdersAsync())
            newtask = newtask.ContinueWith(Sub() account.LogFinishTask("Getting Orders", starttime))
    
            tasklist.Add(newtask)
        Next
    
    
        Await Task.WhenAll(tasklist.ToArray)
        Dim b = 1
    That code gets a compile warning and I am pretty sure I am not doing it right. Basically, instead of continuing newtask with Action(Task), I am continuing it with Function (of Task)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Can we use continuewith to follow a task with another task?

    You are using type inference here:
    vb.net Code:
    1. Dim newtask = account.readbalancesAsync()
    That means that newtask will be whatever type is returned by that method. After that, you can only assign that type to that variable. Is that what you're doing here:
    vb.net Code:
    1. newtask = newtask.ContinueWith(Async Function() account.getOrdersAsync())
    Presumably not.

    That seems a rather odd thing to do anyway. What's the point of getting orders in there if you can't put the result anywhere?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width