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,563
  • 2
  • 36
  • 65
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
  • 138,123
  • 20
  • 222
  • 279