// ----- Private Methods ----- private static void ResetVariables() { m_thread = null; m_stop = false; m_pars = null; m_containingBytes = null; }
private void startButton_Click_1(object sender, EventArgs e) { // Clear the results list: resultsList.Items.Clear(); // Get the parameters for the search thread: String fileNamesString = fileNameTextBox.Text; String[] fileNames = fileNamesString.Split(new Char[] { ';' }); List <String> validFileNames = new List <String>(); foreach (String fileName in fileNames) { String trimmedFileName = fileName.Trim(); if (trimmedFileName != "") { validFileNames.Add(trimmedFileName); } } Encoding encoding = asciiRadioButton.Checked ? Encoding.ASCII : Encoding.Unicode; File_SearcherParams pars = new File_SearcherParams(searchDirTextBox.Text.Trim(), includeSubDirsCheckBox.Checked, validFileNames, newerThanCheckBox.Checked, newerThanDateTimePicker.Value, olderThanCheckBox.Checked, olderThanDateTimePicker.Value, containingCheckBox.Checked, containingTextBox.Text.Trim(), encoding); // Start the search thread if it is not already running: if (File_Searcher.Start(pars)) { // Disable all buttons except stop button: DisableButtons(); } else { MessageBox.Show("The searcher is already running.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
// ----- Public Methods ----- public static Boolean Start(File_SearcherParams pars) { Boolean success = false; if (m_thread == null) { // Perform a reset of all variables, // to ensure that the state of the searcher is the same on every new start: ResetVariables(); // Remember the parameters: m_pars = pars; // Start searching for FileSystemInfos that match the parameters: m_thread = new Thread(new ThreadStart(SearchThread)); m_thread.Start(); success = true; } return(success); }