How to read all .txt in a folder into a thread pool

simpleonline

Active member
Joined
Sep 13, 2011
Messages
33
Programming Experience
Beginner
Hey guys. I am going to implements a thread pool to run my application. All of my content is saved under a folder on my desktop.

Each of the files are in .txt format. How can I read each .txt from a given folder and then put the .txt file into the thread pool / thread queue?

Thanks
 
E.g.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    For Each filePath In IO.Directory.GetFiles(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "*.txt")
        ThreadPool.QueueUserWorkItem(AddressOf ProcessFile, filePath)
    Next
End Sub

Private Sub ProcessFile(filePath As Object)
    Dim fileContents = IO.File.ReadAllText(CStr(filePath))

    'Use contents here.
End Sub
 
Back
Top