View Single Post
  #3 (permalink)  
Old November 28th, 2013, 02:20 AM
Wendel Wendel is offline
Authorized User
Points: 96, Level: 1
Points: 96, Level: 1 Points: 96, Level: 1 Points: 96, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default HowT

Hi
Lesson37TryIt_LINQtoObjects_AddProgressBar
Thanks for your prompt response. I added you sample code for “BackgroundWorker and “ProgressBar” to my code and it works as expected (i.e. it produces a progessBar for a duration of 1 * 10 * 10 *1000 milliseconds).

You were saying that using “Directory.GetFiles” does not return until it is finished. So I presume that is not an option for counting say 100 files, it will only produce a total count of files found..
1) How can I find and display every say 100 files as they are found and then all files.
2) How can I update the display in a label or listBox every time I find say 100 files.
3) How can I refresh the label or list box say every 100 files
4) Is the refresh done in the main program “….Button_Click(object sender,EventArgs e)” or in the “..Background worker_DoWork…”
5) Help shows refresh as “public override void Refresh () “. Not sure where this code should go.

In attached code I have displayed a count of total files in:
Code:
this.Text = ("Number of files found: " + countLBItems);
Regards
Wendel

Code:
            // Get the file pattern and target string.
            string pattern = patternComboBox.Text;
            string target = targetTextBox.Text.ToLower();
            string writeDate = writeDateTimePicker.Text;

            // Search for files.
            DirectoryInfo dirinfo = 
                new DirectoryInfo(directoryTextBox.Text);
            var fileQuery =
                from FileInfo fileinfo
                in dirinfo.GetFiles(pattern, SearchOption.AllDirectories)
                where
                 (File.ReadAllText(fileinfo.FullName).ToLower().Contains(target) &&
                 (fileinfo.LastWriteTime.Subtract(DateTime.Now).TotalDays >= -noDays))
select (fileinfo.Length.ToString() + "\t" + fileinfo.FullName + "\t" +     fileinfo.LastWriteTime);

            //Display result
            fileListBox.DataSource = fileQuery.ToArray();
            int countLBItems = fileListBox.Items.Count;
            this.Text = ("Number of files found: " + countLBItems);
            MessageBox.Show("Done");