I must be missing something,
var t2 = new Task<bool>(() =>
{
return UserName == "Admin";
});
bool x = await t2;
The bool x = await t2;
is never finished, x
doesn't receive anything (while I made sure that UserName is equal to "Admin"), don't know exactly what is going on, please someone can explain to me .
You haven't started the task. await
will wait until it completes, but it's never going to complete if it doesn't get started.
Perhaps you wanted Task.Run
, which creates and starts a task? (I assume that in reality, your task does something more useful...)
See more on this question at Stackoverflow