.net core中的简单异步实现
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> 异步方法返回值 getdatatask = Task<ReturnDto<GetReportData>>.Run(() => //your method ); result = getdatatask.Result; //获取上面异步方法执行后的值,在这边会阻塞线程,等到上面异步方法执行完毕