线程异步操作,更新其中一个报错不影响另一个的运行(Task )

时间:2021-12-22 15:23:34

//子系统同步更新
                BD001_BLL bll = new BD001_BLL();
                List<BD001_Model> list = bll.GetModelListByuserid(model.BD010_001);
                foreach (BD001_Model item in  list)
                {
                    BD017_BLL itembll = new BD017_BLL();
                    BD017_Model itemmodel = itembll.GetModel(item.BD001_001);
                    itemmodel.BD017_002 = model_BD010.BD010_011;
                    itemmodel.BD017_003 = model_BD010.BD009_001;
                    itemmodel.BD017_004 = model_BD010.BD010_002;
                    itemmodel.BD017_005 = model_BD010.BD010_003;
                    itemmodel.BD017_007 = model_BD010.BD010_005;
                    itemmodel.BD017_008 = model_BD010.BD010_006;
                    itemmodel.BD017_009 = model_BD010.BD010_007;
                    ResultManage<string, bool> result;
                    Task task = new Task(new Action(() =>
                    {
                        IOC ioc = new IOC();
                        ioc.Create(item.BD001_005, item.BD001_900, item.BD001_007, item.BD001_008, item.BD001_006);
                        if (ioc.abstract_factory.UserInfoManage.Exists(itemmodel).Manage == "true")
                        {
                           result=  ioc.abstract_factory.UserInfoManage.Update(itemmodel);
                        }

else
                        {
                           result= ioc.abstract_factory.UserInfoManage.Add(itemmodel);
                        }
                        MessageBox.Show(result.Manage+item.BD001_006  );
                    }));
                    task.Start();
                }