Reputation: 24562
I am calling a task like this in my method:
if (Settings.mode.IsPractice() && App.practiceRunning != true)
{
// I want to call this method and check if it returned true or false
await IsPractice();
}
private async Task IsPractice()
{
// I want to return true or false from here
}
How can I return from the method based on the value of the IsPractice() returning a true or false? Looks like the async method returns just a Task but I need to know if it ran and returned a true or a false.
Upvotes: 3
Views: 3503
Reputation: 1583
private static async Task<bool> IsPractice()
{
return true;
}
and in async method receive like this
bool x = await IsPractice();
Upvotes: 2
Reputation: 2679
just add <bool>
private async Task<bool> IsPractice()
{
return true;
}
or just use async bool
private async bool IsPractice()
{
return true;
}
Upvotes: 1
Reputation: 1809
Use the generic Task type:
if (Settings.mode.IsPractice() && App.practiceRunning != true)
{
if (await IsPractice()) {
// Do something here
}
}
private async Task<bool> IsPractice()
{
return true;
}
Upvotes: 3