Skip to main content
edited tags; indentation
Source Link
svick
  • 244.3k
  • 53
  • 403
  • 526

I read many articles on async and await(mostly from msdn - which is good actually). There is still one question that bothers me and I could not find the answer.

If there is an await statement on a task then the control is returned to its caller until it is awaited again in the caller. In that case is this time consuming task getting executed in a separate thread? If not then how is it getting executed parallel to the main thread.

async Task<string> GetContentsAsync()
        {
                int sample = 0;
              HttpClient client = new HttpClient();
            Task<string> contents = client.GetStringAsync("http://www.microsoft.com");
            
            string data = await contents;
            return data;
        }

I Hopehope my question is clear.

I read many articles on async and await(mostly from msdn - which is good actually). There is still one question that bothers me and I could not find the answer.

If there is an await statement on a task then the control is returned to its caller until it is awaited again in the caller. In that case is this time consuming task getting executed in a separate thread? If not then how is it getting executed parallel to the main thread.

async Task<string> GetContentsAsync()
        {
                int sample = 0;
              HttpClient client = new HttpClient();
            Task<string> contents = client.GetStringAsync("http://www.microsoft.com");
            
            string data = await contents;
            return data;
        }

I Hope my question is clear.

I read many articles on async and await(mostly from msdn - which is good actually). There is still one question that bothers me and I could not find the answer.

If there is an await statement on a task then the control is returned to its caller until it is awaited again in the caller. In that case is this time consuming task getting executed in a separate thread? If not then how is it getting executed parallel to the main thread.

async Task<string> GetContentsAsync()
{
    int sample = 0;
    HttpClient client = new HttpClient();
    Task<string> contents = client.GetStringAsync("http://www.microsoft.com");
            
    string data = await contents;
    return data;
}

I hope my question is clear.

added 352 characters in body
Source Link
ckv
  • 10.8k
  • 20
  • 102
  • 151

I read many articles on async and await(mostly from msdn - which is good actually). There is still one question that bothers me and I could not find the answer.

If there is an await statement on a task then the control is returned to its caller until it is awaited again in the caller. In that case is this time consuming task getting executed in a separate thread? If not then how is it getting executed parallel to the main thread.

async Task<string> GetContentsAsync()
        {
            int sample = 0;
            HttpClient client = new HttpClient();
            Task<string> contents = client.GetStringAsync("http://www.microsoft.com");
            
            string data = await contents;
            return data;
        }

I Hope my question is clear.

I read many articles on async and await(mostly from msdn - which is good actually). There is still one question that bothers me and I could not find the answer.

If there is an await statement on a task then the control is returned to its caller until it is awaited again in the caller. In that case is this time consuming task getting executed in a separate thread? If not then how is it getting executed parallel to the main thread.

I Hope my question is clear.

I read many articles on async and await(mostly from msdn - which is good actually). There is still one question that bothers me and I could not find the answer.

If there is an await statement on a task then the control is returned to its caller until it is awaited again in the caller. In that case is this time consuming task getting executed in a separate thread? If not then how is it getting executed parallel to the main thread.

async Task<string> GetContentsAsync()
        {
            int sample = 0;
            HttpClient client = new HttpClient();
            Task<string> contents = client.GetStringAsync("http://www.microsoft.com");
            
            string data = await contents;
            return data;
        }

I Hope my question is clear.

Source Link
ckv
  • 10.8k
  • 20
  • 102
  • 151

Clarification needed on async and await

I read many articles on async and await(mostly from msdn - which is good actually). There is still one question that bothers me and I could not find the answer.

If there is an await statement on a task then the control is returned to its caller until it is awaited again in the caller. In that case is this time consuming task getting executed in a separate thread? If not then how is it getting executed parallel to the main thread.

I Hope my question is clear.