I have 2 async functions that I execute and return an integer. When I try to access the return value, the IDE complains that the tasks are void type, not int type.
private async Task<int> func01(int _i1, int _i2)
{
return await Task.Run(async () => {
await Task.Delay(1000);
return 1;
});
}
private async Task<int> func02(string _i1, string_i2)
{
return await Task.Run(async () => {
await Task.Delay(3000);
return 1;
});
}
Task _t1 = func01(1, 3);
Task _t2 = func02("Hello", "World");
int _r1 = await _t1; //here, IDE says that _t1 and _t2 are void types
int _r2 = await _t2;
How do I return a value from an async task?
Taskinstead ofTask<int>