[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

How to really develop a multithreading application ?

I'm trying to write a simple URL downloader.

But I want a real mutithreading, For example I have 100 website and I want to download them 20 by 20. threadcount = 20


I want to use threadpool, but I don't know how. I couldn't find any real solution in anywhere about this.

Simply;
My save class is
====================================
Class savePage
    Public url, filename As String

    Public Sub save()
        Dim wc As New WebClient
        wc.DownloadFile(url, filename)
    End Sub

End Class
====================================

Now I want to save 100 URL multithreaded (threadpool).

Thanks;
0
herterx
Asked:
herterx
  • 2
1 Solution
 
AmanBrarCommented:
Imports System
Imports System.Threading

Public Class Example
    Public Shared Sub Main()
        ' Queue the task.
        ThreadPool.QueueUserWorkItem(AddressOf ThreadProc)
       
        Console.WriteLine("Main thread does some work, then sleeps.")
        ' If you comment out the Sleep, the main thread exits before
        ' the thread pool task runs.  The thread pool uses background
        ' threads, which do not keep the application running.  (This
        ' is a simple example of a race condition.)
        Thread.Sleep(1000)

        Console.WriteLine("Main thread exits.")
    End Sub

    ' This thread procedure performs the task.
    Shared Sub ThreadProc(stateInfo As Object)
        ' No state object was passed to QueueUserWorkItem, so
        ' stateInfo is null.
        Console.WriteLine("Hello from the thread pool.")
    End Sub
End Class

0
 
AmanBrarCommented:
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now