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

  • Home
  • SEARCH
  • 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 9129669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:48:06+00:00 2026-06-17T07:48:06+00:00

So I have a folder with several files. I have a loop that will

  • 0

So I have a folder with several files. I have a loop that will go through each file and add it to a thread to process in the background so the UI is responsive. The problem is I want to only have one thread running at a given time. So basically I want to “queue” the threads and when one completes fire off the next one. What would be the best way to do this? Here is the code I am using. I am wondering if a timer is the best solution? Thanks everyone.

foreach (CustomerFile f in CF)
{
    btnGo.Enabled = false;
    UpdateProgressDelegate showProgress = new UpdateProgressDelegate(UpdateProgress);
    ProcessFile pf = new ProcessFile(this, showProgress, f._FileName, txtDestFolder.Text);
    Thread t = new Thread(new ThreadStart(pf.DoWork));
    t.IsBackground = true; 
    t.Start();
}
  • 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-06-17T07:48:07+00:00Added an answer on June 17, 2026 at 7:48 am

    How about add the files to a queue and process the queue on a another thread?

    Queue<CustomerFile> files = new Queue<CustomerFile>()
    foreach (CustomerFile f in CF)
      files.Enqueue(f);
    
    BackgroundWorker bwk = new BackgroundWorker();
    bwk.DoWork+=()=>{
        //Process the queue here
        // if you update the UI don't forget to call that on the UI thread
    };
    
    bwk.RunWorkerAsync();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several hundred files in a folder. Each of these file is a
I have a folder in my WPF app Images that has several .png files
In my home folder in Linux I have several config files that have rc
I have a folder called code/ which has several .cpp files, that all need
I have a directory that contains several files. I want compress this folder to
I have several files that were uploaded and files are grouped in a folder.
I have a folder with several excel files that have a date field, i.e.
I have a folder in C:\Name\Folder\ and in that I have several files. I
I have a folder /mnt/sdcard/Bluetooth which contains several zip files. Each of this zip-files
I have several files to be saved in the Documents folder, this list of

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.