Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4614726
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:44:26+00:00 2026-05-22T01:44:26+00:00

Good evening, Following is the code I used for reading the files and folders

  • 0

Good evening,

Following is the code I used for reading the files and folders from a drive etc.

Public Class LoadingBox

    Public counter As ULong
    Public OpenRecords As New Dictionary(Of String, MainWindow.records)
    Public Path As String
    Public Diskname As String
    Private WithEvents BKWorker As New BackgroundWorker()


    Public Sub New(ByVal _Path As String, ByVal _Diskname As String)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Path = _path
        Diskname = _diskname
    End Sub

    Private Sub GetStructure(ByVal tempdir As String, ByVal ParentID As String, ByVal DiskName As String)
        Dim maindir As DirectoryInfo = My.Computer.FileSystem.GetDirectoryInfo(tempdir)
        For Each Dir As DirectoryInfo In maindir.GetDirectories
            Try
                Dim d As New MainWindow.records
                d.Filename = Dir.Name
                d.Folder = True
                d.Rowid = Date.UtcNow.ToString() + counter.ToString()
                d.Size = 0
                d.ParentID = ParentID
                d.DiskName = DiskName
                d.DateCreated = Dir.CreationTimeUtc
                d.DateModified = Dir.LastWriteTimeUtc
                OpenRecords.Add(d.Rowid, d)
                'Label1.Content = "Processing: " + Dir.FullName
                BKWorker.ReportProgress(0, Dir.FullName)
                counter = counter + 1
                GetStructure(Dir.FullName, d.Rowid, DiskName)
            Catch ex As Exception

            End Try


        Next
        For Each fil As FileInfo In maindir.GetFiles
            Try
                Dim d As New MainWindow.records
                d.Filename = fil.Name
                d.Folder = False
                d.Rowid = Date.UtcNow.ToString() + counter.ToString()
                d.Size = fil.Length
                d.ParentID = ParentID
                d.DiskName = DiskName
                d.DateCreated = fil.CreationTimeUtc
                d.DateModified = fil.LastWriteTimeUtc
                OpenRecords.Add(d.Rowid, d)
                'Label1.Content = "Processing: " + fil.FullName
                BKWorker.ReportProgress(0, fil.FullName)
                counter = counter + 1
            Catch ex As Exception

            End Try

        Next
    End Sub

    Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        counter = 0
        BKWorker.WorkerReportsProgress = True
        AddHandler BKWorker.DoWork, AddressOf BKWorker_Do
        AddHandler BKWorker.ProgressChanged, AddressOf BKWorker_Progress
        AddHandler BKWorker.RunWorkerCompleted, AddressOf BKWorker_Completed
        BKWorker.RunWorkerAsync()

        'GetStructure(Path, "0", Diskname)
    End Sub

    Private Sub BKWorker_Do(ByVal sender As Object, ByVal e As DoWorkEventArgs)
        'Throw New NotImplementedException
        GetStructure(Path, "0", Diskname)
    End Sub

    Private Sub BKWorker_Progress(ByVal sender As Object, ByVal e As ProgressChangedEventArgs)
        'Throw New NotImplementedException
        Label1.Content = "Processing: " + e.UserState.ToString()
        If ProgressBar1.Value = 100 Then
            ProgressBar1.Value = 0
        End If
        ProgressBar1.Value = ProgressBar1.Value + 1
    End Sub

    Private Sub BKWorker_Completed(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
        'Throw New NotImplementedException
        MessageBox.Show("Completed")
        Me.Close()
    End Sub
End Class

However the problem is that, the background thread is able to read files very fast, but the UI thread is not able to keep up the speed with it, could you please advice me on how I can solve this issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:44:26+00:00Added an answer on May 22, 2026 at 1:44 am

    One quick answer would be to only report the progress when a certain amount of time has passed that way if 10 files were processed in that time the UI isn’t trying to update one each one. If things are processing that fast then you really don’t need to update the user on every single file.

    Also on a quick side note if your ProgressBar isn’t actually reporting progress from 0 to 100% you might want to just set its IsIndeterminate property to true instead of increasing the percent and then resetting it back to 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening, I created a class which inherits from UIViewController and i created a
I want to split the following string Good^Evening i used split option it is
Good evening, I wrote the code below in C to read and print from
Good evening everyone Suppose your code has the following statement: if (string ends with
Good evening, In my app that I'm currently developing, I have a class that
Good Evening All, I've created the following stored procedure: CREATE PROCEDURE AddQuote -- Add
Good evening everyone, I am using a JavaScript to load/override content from an HTML-File
Good evening :-)! I have this code to use Drag & Drop method for
Good evening. This code works. It sorts an array of cards by both Suit
Good evening fellow computational authors, I'm trying to run the following script: find .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.