I have the following code:
public async Task GetData(Uri source)
{
if (client.IsBusy == true)
client.CancelAsync ();
Task
aysnc marks the method as being asynchronous. await is where execution will continue from WHEN the result comes back from the call.
when you make the request to get tskResult execution cannot complete the following steps as execution has to wait (potentially many clock cycles) so it skips out of this method after first putting down a marker as to where it should return.
When DownloadStringTaskAsync has completed it will come back to this method and ONLY then assign a result. In real time this could be millions of CPU clock cycles after the call was initiated., stepping trough wit the debugger one line at a time you will see the jump and later the call back.
put you break point on return strResult and don't step through. just wait for the call to come back after the client.DownloadStringTaskAsync returns.
Also if during the execution of this method there is an exception then this will be "consumes" by the method so if the code does not break on your return then wrap the whole block in a try catch and also put a breakpoint inside the catch - so you can see what exception you're getting.
An async
method returns as soon as an await
statement is reached, if the thing awaited hasn't finished. Once it completes, the method continues execution after that await
statement. Try putting a break point on the return statement and it should get hit twice.