I'm trying to run a long list (an entire domain's users) in a thread. If I don't run the function as a thread it runs fine. But if I put it in a thread I get an error at run-time.

Code:
private void RunThread()
{
     Domain3 localDomain = GetDomain();  // callback function
     users = GetUsersList();                         // callback function

      object[] fields = new object [datADGrid.Columns.Count];
            
      foreach (User3 user in users)  // complains that it fails to match target type
     {
         fields [0] = user.Name;

         int index = 1;

.
.
The problem is in the foreach loop where, apparently, 'user' isn't of the same type as the components of the 'users' collection yet this same code works fine when run under a non-thread function. As a thread and as a stand-alone function the code calls the same callback functions to get the Domain and the Users.

This is the callbackfunction for returning the User list. users is already set to reference domain.Users.

Code:
private Users  GetUsersList()
{
    if (this.InvokeRequired)
    {
        GetUsers d = new GetUsers(GetUsersList);
        this.Invoke(d, new object[] { });
        return users;
    }
    else
    {
        return users;
    }
}
I might add that I've also tried the User5 class.