Task的用法
作者:互联网
public void ReportDataService(string servicesName) { this.ServicesName = servicesName; DataExportPlan dataExportPlan = new DataExportPlan(); //查询数据 NewEventLog.WriteLog(ServicesName, "服务开始执行"); try { DataTable dt = dataExportPlan.GetDataExportPlan(); if (dt != null) { IList<Task> tasks = new List<Task>(); foreach (DataRow item in dt.Rows) { Task<bool> task = new Task<bool>(TaskHandle, item); task.Start(); tasks.Add(task); NewEventLog.WriteLog(ServicesName, "方法[" + planOper.MethodName + "]开始执行");
} Task.WaitAll(tasks.ToArray()); } } catch (Exception ex) { NewEventLog.WriteLog(ServicesName, "服务执行异常:" + ex.Message); } NewEventLog.WriteLog(ServicesName, "服务执行结束"); }
public bool TaskHandle(object objectItem) { int PlanID = 0; bool success = true;return success; }
标签:tasks,NewEventLog,WriteLog,用法,Task,new,ServicesName 来源: https://www.cnblogs.com/123qq/p/9848300.html