Remembering Thoughts
  Twitter GitHub RSS

Winforms UI cross thread operations

ThreadPool.QueueUserWorkItem(new WaitCallback(LoadUsers));

private void LoadUsers(Object stateInfo)
{
 var site = new SPSite(testHarnessSettings.Url);

 var web = site.OpenWeb();

  foreach(SPUser user in web.AllUsers)
  {
   if (usersListBox.InvokeRequired)
   {
         usersListBox.Invoke(  
          new MethodInvoker(
         delegate { usersListBox.Items.Add((user.LoginName));  
   }));
  }
}

Published:

Share on Twitter