我有几个绑定到 LDAP 数据源的 DropDownLists。由于它们需要一段时间才能加载,因此我想尝试减轻多线程对性能的影响。但是,当我运行以下代码时,我分配给线程的方法似乎没有执行。在编译或运行时没有抛出任何错误。DropDownLists 只是保持未绑定。如果我不穿线,这两种方法都可以正常工作。
if (DropDownListOwner.Items.Count == 0)
{
Thread t = new Thread(BindDropDownListOwner);
t.Start();
}
if (DropDownListAddEditRecipients.Items.Count == 0)
{
Thread t2 = new Thread(BindDropDownListAddEditRecipients);
t2.Start();
}
// Delegate Methods
public void BindDropDownListOwner()
{
List<KeyValuePair<string, string>> emp = EmployeeList.emplList("SAMAccountName", "DisplayName");
DropDownListOwner.DataSource = emp.OrderBy(item => item.Value);
DropDownListOwner.DataTextField = "Value";
DropDownListOwner.DataValueField = "Key";
DropDownListOwner.DataBind();
}
public void BindDropDownListAddEditRecipients()
{
List<KeyValuePair<string, string>> emp2 = EmployeeList.emplList("Mail", "DisplayName");
DropDownListAddEditRecipients.DataSource = emp2.OrderBy(item => item.Value);
DropDownListAddEditRecipients.DataTextField = "Value";
DropDownListAddEditRecipients.DataValueField = "Key";
DropDownListAddEditRecipients.DataBind();
}