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();
}