Hi friends,
I have a windows application(vb.net) in which i want to retrieve informations from 3 websites(after authentication).here i have a list of customer details.based on the customer details application have to decide where to retrieve data(i mean among the 3 websites).now i am able to retrieve informations by giving customerdetails(his id and number) one by one.but as it is a very lengthy and time consuming,i need it to be done once i click a button after giving login details and other necessary inputs.now i have 2 questions.
1.Is it correct to go for threading concept?(creating a seperate thread for each set of inputs concurrently)?
2.if so,how?
Any reference article or suggestion would be appreciated.TThank u in advance.

Dani AI

Generated

Short answer: yes — concurrency is the right approach. You have many independent, I/O-bound network calls (authentication + fetching). Rather than creating one OS thread per customer, use asynchronous I/O with a bounded-concurrency pattern so the UI stays responsive and you don't overwhelm the remote sites or your machine.

A simple, modern pattern (VB.NET, .NET 4.5+) is: reuse a single HttpClient (with a CookieContainer or token for authenticated sessions), use Async/Await for non-blocking calls, and limit parallelism with SemaphoreSlim. Example:

Dim handler = New HttpClientHandler() With {.UseCookies = True, .CookieContainer = New System.Net.CookieContainer()}
Dim http = New HttpClient(handler)
Dim sem = New System.Threading.SemaphoreSlim(5) ' max concurrent requests

Async Function FetchForCustomerAsync(cust As Customer) As Task
    Await sem.WaitAsync()
    Try
        Dim url = ChooseUrlForCustomer(cust)
        Dim resp = Await http.GetAsync(url)
        resp.EnsureSuccessStatusCode()
        Dim body = Await resp.Content.ReadAsStringAsync()
        ' store result into a thread-safe collection
    Finally
        sem.Release()
    End Try
End Function

Async Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
    btnGo.Enabled = False
    Dim tasks = customers.Select(Function(c) FetchForCustomerAsync(c)).ToArray()
    Await Task.WhenAll(tasks)
    btnGo.Enabled = True
End Sub

Practical notes and troubleshooting: authenticate once per site and reuse the token/cookie container (avoid logging in for every customer); if customers use different credentials, create a per-credential HttpClient/handler. Report progress to the UI using Progress(Of T) or TaskScheduler.FromCurrentSynchronizationContext — do not touch controls from background threads. Add timeouts, retries with exponential backoff, and respect remote rate limits (start with 4–8 concurrent requests). Avoid blocking calls (no Thread.Sleep or .Result/.Wait on Tasks).

As pointed you toward threading APIs, the above extends that advice: use async/TPL for clarity and scalability rather than raw threads or one thread per customer.

Recommended Answers

All 2 Replies

thank you...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.