.net core of simple asynchronous implementation

 List<Task> alltask = new List<Task>();
Task task1 = null;
task1 = Task.Run(() =>  //无参数启动异步
                            {
                                //your methods
                            });




if (task1 != null) { alltask.Add(task1); }

 Task.WaitAll(alltask.ToArray());

  

Task <ReturnDto <GetReportData >> getdatatask = null; // ReturnDto <GetReportData> asynchronous method returns a value 
 getdatatask the Task = <ReturnDto <>> GetReportData the Run (() =>. 
  // your Method 
); 
Result = getdatatask.Result; / / get values above asynchronous method execution, the thread will block here, until the completion of the above asynchronous method execution

  

Guess you like

Origin www.cnblogs.com/fishyues/p/11672395.html