这是我的ActionMethod:public IActionResult GetMember(string BCode){ Info model = new Info(); try { model.BList = GetBList(); if (BCode != null) { model.MemberList = GetMemberList(BCode); } } catch (Exception ex) { TempData["Msg"] = ex.Message; } finally { } return View("Index", model);}public List<PendingListBranchWise> GetBList() { using (IDbConnection db = new SqlConnection(configuration.GetConnectionString("constr"))) { return (List<PendingListBranchWise>)db.Query<PendingListBranchWise>("sp_GetClientDetails", new { value = "GetBranchList" }, commandType: CommandType.StoredProcedure); } }public List<pendingListMemberWise> GetMemberList(string BCode) { using (IDbConnection db = new SqlConnection(configuration.GetConnectionString("constr"))) { return (List<pendingListMemberWise>)db.Query<pendingListMemberWise>("sp_GetClientDetails", new { value = BCode }, commandType: CommandType.StoredProcedure); } }这是一个简单的代码,运行两个方法返回 List<SelectListItem>model.BList = GetBList();model.MemberList = GetMemberList(BCode);我不想以顺序方式运行它们,因为它们彼此独立,因此对我来说可用的选项是使用线程:Thread t = new Thread(new ThreadStart(GetBList));t.Start();t.Join();它有效 如果GetBranchList()没有返回类型,但我需要返回List<SelectListItem>.它显示编译错误List<PendingListBranchWise> GetBranchList()' 有错误的返回类型List在单独的线程上运行时如何从此方法返回?
2 回答
繁星淼淼
TA贡献1775条经验 获得超11个赞
model.BList = GetBList();
if (BCode != null)
{
model.MemberList = GetMemberList(BCode);
}
可以像这样并行完成:
Parallel.Invoke(
() => { model.BList = GetBList(); },
() => { if (BCode != null) { model.MemberList = GetMemberList(BCode); } }
);
- 2 回答
- 0 关注
- 161 浏览
添加回答
举报
0/150
提交
取消