The difference between waiting and Task.Wait

First way:

var tds=SearchProcess(); await tds; public async Task<XmlElement> SearchProcess() { } 

The second way:

 var tds= Task.Factory.StartNew(()=>SearchProcess()); Task.WaitAll(tds); public XmlElement SearchProcess() { } 

Is there a difference in performance in both of the above approaches?

+6
source share
1 answer

Task.WaitAll blocked, and when using await the async method will execute. To expect multiple tasks asynchronously, you can use Task.WhenAll :

 public async Task DoSomething() { IEnumerable<Task> tds = SearchProcess(); await Task.WhenAll(tds); //continue processing } 
+7
source

All Articles