Difference between await and Task.Wait

c#

Solution

`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    
}

Problem

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?

Original source

Related problems