我写了一个非常简单的c#应用程序,它扫描我们的活动目录以锁定帐户并将用户名返回到列表框(LB1)。这是搜索的代码。它属于Button_Click事件:Winforms使用PrincipalSearcher函数的进度条
try
{
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "DOMAIN", "OU=OUnAme,DC=DOMAIN,DC=com");
UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.Enabled = true;
PrincipalSearcher search = new PrincipalSearcher(qbeUser);
foreach (UserPrincipal user in search.FindAll())
{
if (user.IsAccountLockedOut())
{
LB1.Items.Add(user.SamAccountName.ToString());
}
}
}
是否有一种方法来实现填充FindAll()事件的进度条?我只想先做一个计数函数,来确定进度条的最大值,然后在foreach循环的第一步添加一个incrament?
谢谢 韦斯
没有时间给出一个很好的完整答案,但您可能想查看['BackgroundWorker'](http://msdn.microsoft.com/zh-cn/library/system.componentmodel.backgroundworker %28v = vs.110%29.aspx)组件,因此您可以在不阻止UI线程的情况下执行处理。还请记住[这个问题](http://stackoverflow.com/questions/661561/how-to-update-the-gui-from-another-thread-in-c)详细说明如何更新UI线程从后台线程。 – Anthony 2014-12-03 19:04:23