8

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?

thmshd
  • 5,729
  • 3
  • 39
  • 67
dsaralaya
  • 89
  • 1
  • 3

1 Answers1

8

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    
}
Lee
  • 142,018
  • 20
  • 234
  • 287