Home > DeveloperSection > Forums > Difference between await and Task.Wait
Tanuj Kumar

Total Post:134

Points:940
Posted on    December-27-2013 6:49 AM

 C# C# 
Ratings:


 1 Reply(s)
 2796  View(s)
Rate this:

First way:

var tds=SearchProcess();

await tds;

public async  Task<XmlElement> SearchProcess()

{

}

Second way:

var tds= Task.Factory.StartNew(()=>SearchProcess());

Task.WaitAll(tds);

public XmlElement SearchProcess()

{

}

In above both approach any performance difference is there?



Alex Leblois
Alex Leblois

Total Post:67

Points:471
Posted on    December-27-2013 7:39 AM

Hi Tanuj,

Task.WaitAll is blocking, while using await will make the containing method async. To wait for multiple tasks asynchronously you can use Task.WhenAll:

public async Task DoSomething()

{

    IEnumerable<Task> tds = SearchProcess();

    await Task.WhenAll(tds);

    //continue processing   

}


Don't want to miss updates? Please click the below button!

Follow MindStick