This is my 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);
}
}
It's a simple code, running two methods returning List<SelectListItem>
model.BList = GetBList();
model.MemberList = GetMemberList(BCode);
I don't want to run them in a sequential way as they are independent of each other, so the available option for me is to use threading:
Thread t = new Thread(new ThreadStart(GetBList));
t.Start();
t.Join();
It works If GetBranchList()
does not have a return type, but I need to return List<SelectListItem>
.
It shows a compilation error
List<PendingListBranchWise> GetBranchList()
' has the wrong return type
How to return the List
from this method while running it on a separate thread?