i am new to metro application development, i request you to help me understand the usage of async and await key words ,
As per my knowledge i understood that we async and await both simultaneously.
But if one method / function is mention as async :-
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
Uri inputUri = new Uri("http://examplewebservices");
try
{
string result = await httpClient.GetStringAsync(inputUri);
///
i have to do some operations on this string result here
///
}
catch (Exception ex)
{
}
}
1)what happens will a separate thread is created ?, and every thing inside that runs asynchronously ?
2)What will await keyword do here ?
3)if it is asynchronous , there is place in the code where i need to perform some operations on string result , if that is not completed it would show a error right ?
Please guide me out.
Thanks in Advance.
Please read my
async/awaitintro.No.
asyncmethods are synchronous until theyawaitan operation that isn’t completed.It will asynchronously wait until the operation completes.
In this case, it will return back to the message loop and schedule the remainder of the method to run (on the UI thread) after the download completes.
No. Because of the
await, the rest of the method won’t run until the download is complete.