Question : Implementing Multithreading to increase performance.

I am using ASP.Membership, Roles and Profiles in my WinForms and Web application.  I have serialized the profile information which is stored in SQL.  Because of the way I have serialized the object creating the profile objects take some time.  So if I open my app as an administrator and open the form that displays all the users in a grid that contains the Membership.Username, Profile.FirstName, Profile.LastName and Profile.PrimaryRole.  It takes approximately 40 seconds to display the 279 users. As an admin I can see all users  which takes along time to process.  

Basically I start with a list of UserNames that I iterate through.  I have created a SimpleUserInfo class and a SimpleUserInfoCollection that is used to populate the grid.

For each UserName as String in UserNames
  SimpleUserBindingSource.Add( GetSimpleUserInfo(UserName))
Next.

I could create a thread for each call to GetSimpleUserInfo but that would create at the moment 279 threads.  I have read that creating too many threads would slow down performance.

My UserNames is in Alphabetical order so using different threads does not guarantee that each thread will return in the order they were started.

This is what I would like to accomplish.

Use approximatelly 4 threads to retreive the data passing one username.
Add the information to the grid in username order as each thread is finished.  
Be able to select an item on the grid and keep it selected as the grid is updated.
Be able to show the progress in a progress bar.  And also capture when all the threads are complete.

I am attaching a simple Winforms app that simulates the long process.  I am using the DirectoryInfo and FileInfo of MyDocuments to populate the grid.  I have put a random delay to simulate that each call takes a differnt amount of time.  Currently the app is using an individual thread for each call.  

Answer : Implementing Multithreading to increase performance.

Here is an auto translated version. If this doesn't work let me know
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Public Sub ExecuteMethod()
     Try
         If _callback IsNot Nothing Then
             Me.Callback(_state)
         Else
             Me.Simple()
         End If
     Catch exception As Exception
        Me.Exception = exception
     End Try
End Sub
Random Solutions  
 
programming4us programming4us