Hi there. In my application I have a loop that makes calls to a website to download data. I'm using a DownloadDataAsynch call with a handler.

I'm making many such calls in a loop. What I'd like to do is, if I have more than a certain number of replies pending, I should pause the loop and let the data handlers run.

How do I do that?

Code:
     Dim DataReader As SqlDataReader = sp_call.ExecuteReader
     Dim count As Integer = 0
     
     '---------------------------
     ' loop through results  
     ' get description for 
     ' each item on the list
     '---------------------------
     While DataReader.Read()
            ' get the item ID
            Dim itemID As String = DataReader(0).ToString
            Dim request_string As String

            'get the data for that item
            request_string =   [  web request constructed using item no ] 

            ' create an asynchronous call
            Dim data_downloader As New WebClient
            AddHandler data_downloader.DownloadDataCompleted, AddressOf Data_Downloader_complete
            data_downloader.DownloadDataAsync(New Uri(request_string), count)
            items_pending = items_pending + 1
               
            If items_pending > 50 Then
                 [ pause until items_pending < 50 ]
            End If

      End While