I have a piece of code:
...
await func();
where function "func" is defined as:
private Task func()
{
}
and this function definition gives an error:
func(): not all code paths return a value.
What kind of value it requires from me here?
I have a piece of code:
...
await func();
where function "func" is defined as:
private Task func()
{
}
and this function definition gives an error:
func(): not all code paths return a value.
What kind of value it requires from me here?
you are missing the async
keyword in your function:
private async Task func()
{
}
Without it you are defining a function that is returning an object of type Task
but you have no row of return someTask;
and therefore get that compilation error. So unless you add it you will have to return some task.
Otherwise, when specifying the async
keyword you state that this function will be executing some code that can be awaited. If in it you do not await
any Task
you will receive a warning of: "This async method lacks 'await' operators and will run synchronously."
. For more about the warning message read this question.
This will explain better How and When to use async
and await
You have a return type for the method but you don't return anything.
private Task func()
{
return new Task();//the task
}