Return Task<bool> instantly

in .NET 4.5 you can use FromResult to immediately return a result for your task.

public Task<bool> MyTask()
{
    return TaskEx.FromResult(false);
}

http://msdn.microsoft.com/en-us/library/hh228607%28v=vs.110%29.aspx


For Windows Phone 8.1 and higher, the API has been merged to be consistent with other platforms:

public Task<bool> MyTask()
{
    return Task.FromResult(false);
}

Prior to .NET 4.5, you can use TaskCompletionSource<TResult> to simulate the FromResult method.

public static Task<TResult> FromResult<TResult>(TResult result)
{
    var completionSource = new TaskCompletionSource<TResult>();
    completionSource.SetResult(result);
    return completionSource.Task;
}