0

Basically, it asks for a sub with Task as a parameter. That's what Action(of Task) right?

Why?

I know I can pass normal sub to continueWith. I never remember passing a sub that requires a task parameter.

user4951
  • 32,206
  • 53
  • 172
  • 282
  • You call `ContinueWith` on a `Task` and that same `Task` is then received by the `Action` doing the continuing. The idea is that it may well need to know what happened in the previous step in order to determine what to do. – jmcilhinney May 14 '19 at 19:28

1 Answers1

1

It is by the definition. 'ContinueWith' should in most cases operate with the result of 'antecedent' task. If you forget how to call 'ContinueWith', Visual Studio 'Peek Definition' will help you. So, right clicking on 'ContinueWith' and by choosing 'Peek Definition' you will examine the signature. Basically, it looks like is shown in the snippet below.

 public Task<TNewResult> ContinueWith<TNewResult>(
      Func<Task<TResult>, TNewResult> continuationFunction)
    {
      StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
      return this.ContinueWith<TNewResult>(continuationFunction, TaskScheduler.Current, new CancellationToken(), TaskContinuationOptions.None, ref stackMark);
    }

If it is too complicated, you can use a snippet and save an example and then inserted when you need it.

So, let's create an example.

Module Module1

    Sub Main()
        Dim taskA As Task(Of DayOfWeek) = Task.Run(Function() DateTime.Today.DayOfWeek )

        ' Execute the continuation when the antecedent finishes.
        Dim taskB As Task(Of string) = taskA.ContinueWith(Function (antecedent)
            Return $"Today is {antecedent.Result}"
        End Function)


        taskb.Wait()
        Console.WriteLine(taskB.Result)



        Console.ReadLine()
    End Sub

End Module