By Joel Martinez on 5/21/2012

Task .StartNew(() => MakeSomeDecisionSlowly()) .ContinueWith(result => ProcessResult(result));

bool result = await MakeSomeDecisionSlowly(); ProcessResult(result);

public async void DoThatThing() { … }

public async Task<bool> DoThatThing() { … }

Process the results if You have a network connection (common mobile requirement) The server is reachable (what if you're connected at starbucks, but haven't accepted the wifi's terms of use?) The server returns a code 200 (bugs happen) The server indicates that your credentials are ok (what if the user's password expired, or was changed by the user on your website?) The server's json response indicates a successful request

If any of the above conditions are false, notify the user of the problem (with specific text for the situation).

if (HasConnection()) { try { MyObject result = await MakeRemoteAPICall(); ProcessSuccessfulResult(result); } catch(Exception e) { ProcessError(e.Message); } } else { ProcessError("No Connection"); }

Result<MyObject> value = await MakeRemoteAPICall(); if (value.WasSuccessful) { ProcessSuccessfulResult(value.Result); } else { ProcessError(value.ErrorMessage); }

MakeRemoteAPICall( result => ProcessSucessfulResult(result), error => ProcessError(error));