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

 

posted @ 2019-03-11 21:28  木头马尾、、、  阅读(724)  评论(0编辑  收藏  举报