C# C Active Directory应用程序在填充文本框时滞后

C# C Active Directory应用程序在填充文本框时滞后,c#,textbox,active-directory,ldap,C#,Textbox,Active Directory,Ldap,我的任务是创建一个最终的应用程序,该应用程序将与active directory通信并获取所有当前用户。我们正在为所有新用户维护一个旧的excel表问题是,当任何人离开组织时,他们不会被删除,因此新用户会被添加,但旧用户也会留在excel表中,从而导致excel表的增长,因此现在管理层希望 有一个桌面应用程序,他们可以使用它来搜索用户并获取他/她的信息,但我的应用程序滞后,例如用户john被选中,john的电话号码显示为123-456-7890。现在,我在下拉列表中选择最后一个用户Joe,所有信

我的任务是创建一个最终的应用程序,该应用程序将与active directory通信并获取所有当前用户。我们正在为所有新用户维护一个旧的excel表问题是,当任何人离开组织时,他们不会被删除,因此新用户会被添加,但旧用户也会留在excel表中,从而导致excel表的增长,因此现在管理层希望 有一个桌面应用程序,他们可以使用它来搜索用户并获取他/她的信息,但我的应用程序滞后,例如用户john被选中,john的电话号码显示为123-456-7890。现在,我在下拉列表中选择最后一个用户Joe,所有信息都会更改,但电话文本框中仍保留123-456-7890的值。我在这里做错了什么,如果有任何建议或解决办法,我们将不胜感激

 private void ShowUserInformation(SearchResult rs)
    {
        if (rs.GetDirectoryEntry().Properties["samaccountname"].Value != null)
            username.Text = rs.GetDirectoryEntry().Properties["samaccountname"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["givenName"].Value != null)
            FirstName.Text = rs.GetDirectoryEntry().Properties["givenName"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["initials"].Value != null)
            MiddleName.Text = rs.GetDirectoryEntry().Properties["initials"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["sn"].Value != null)
            LastName.Text = rs.GetDirectoryEntry().Properties["sn"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["mail"].Value != null)
            email.Text = rs.GetDirectoryEntry().Properties["mail"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["personalTitle"].Value != null)
            title.Text = rs.GetDirectoryEntry().Properties["personalTitle"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["company"].Value != null)
            company.Text = rs.GetDirectoryEntry().Properties["company"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["l"].Value != null)
            city.Text = rs.GetDirectoryEntry().Properties["l"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["st"].Value != null)
            state.Text = rs.GetDirectoryEntry().Properties["st"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["co"].Value != null)
            country.Text = rs.GetDirectoryEntry().Properties["co"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["memeberOf = IS Team"].Value != null)
            Groups.Text = rs.GetDirectoryEntry().Properties["memeberOf = IS Team"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["postalCode"].Value != null)
            postalcode.Text = rs.GetDirectoryEntry().Properties["postalCode"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["telephoneNumber"].Value != null)
            phone.Text = rs.GetDirectoryEntry().Properties["telephoneNumber"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["streetAddress"].Value != null)
            address.Text = rs.GetDirectoryEntry().Properties["streetAddress"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["department"].Value != null)
            department.Text = rs.GetDirectoryEntry().Properties["department"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["description"].Value != null)
            descriptions.Text = rs.GetDirectoryEntry().Properties["description"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["employeeID"].Value != null)
            employee.Text = rs.GetDirectoryEntry().Properties["employeeID"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["mobile"].Value != null)
            mobile.Text = rs.GetDirectoryEntry().Properties["mobile"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["accountExpires"].Value != null)
            accountexpires.Text = rs.GetDirectoryEntry().Properties["accountExpires"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["homeDrive"].Value != null)
            homedrive.Text = rs.GetDirectoryEntry().Properties["homeDrive"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["homeDirectory"].Value != null)
            homedirectory.Text = rs.GetDirectoryEntry().Properties["homeDirectory"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["whenCreated"].Value != null)
            WhenCreate.Text = rs.GetDirectoryEntry().Properties["whenCreated"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["lastLogoff"].Value != null)
            lastloggedoff.Text = rs.GetDirectoryEntry().Properties["lastLogoff"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["badPasswordTime"].Value != null)
            badpassword.Text = rs.GetDirectoryEntry().Properties["badPasswordTime"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["whenCreated"].Value != null)
            WhenCreate.Text = rs.GetDirectoryEntry().Properties["whenCreated"].Value.ToString();

        if (rs.GetDirectoryEntry().Properties["whenChanged"].Value != null)
            whenchanged.Text = rs.GetDirectoryEntry().Properties["whenChanged"].Value.ToString();

听起来您选择的第二个用户可能没有设置电话号码,因此它没有更新字段。你能在这一行设置断点吗

if (rs.GetDirectoryEntry().Properties["mail"].Value != null)
        email.Text = rs.GetDirectoryEntry().Properties["mail"].Value.ToString();

看看他们的邮件属性是否真的设置好了?

为了修复滞后的文本框变量,我刚刚添加了一个else语句,这就成功了

    if (rs.GetDirectoryEntry().Properties["telephoneNumber"].Value != null)
            phone.Text = rs.GetDirectoryEntry().Properties["telephoneNumber"].Value.ToString();
    else phone.Text = "";

是,添加了断点,设置了mail属性,并且每个用户的mail属性都在更改,就像你说的,如果一个用户没有电话号码,它不会被更新,因此我们正在查看前一个用户的值,但我甚至做了检查,如果我选择了一个没有电话号码的用户,文本框值为空,然后选择一个用户,如果电话号码值发生变化,它仅在选择范围大得多时才滞后,例如选择第一个用户,立即选择最后一个用户会将其丢弃。