AVEbrahimi AVEbrahimi - 1 month ago 6
C# Question

Running another Task after first Task

I have a simple method like this, but I can't run

runAfter
as follows, but compiler says :

Error CS1503 Argument 1: cannot convert from 'System.Threading.Tasks.Task' to 'System.Action'

static async Task TaskSyncWithRemote(string subFolder, Task runAfter)
{
...
some code run here
...
// now I want to run "runAfter", but compiler doesn't like it :)
if (runAfter!=null)
Task.Run(runAfter);
}

Answer

You are trying to pass a Task object to Task.Run() method but compiler is telling you can not :) Compiler is a smart guy, you should listen to him. You can pass for example an Action to Task.Run(). However, I think you are more interested in ContinueWith() method