I'm working on a search program and would like to have a national instruments led control blinking during the search. The led needs to be started on its own thread while the search runs on a separate thread. This is my first attempt at multi-threading in c# and I'm not sure what to try.
Here is my c# code, I'm trying to start the LED blinking then run the search then stop the LED blinking. The LEDON() and LEDOFF() work if run separately.
private void btnSearch_Click(object sender, EventArgs e) { Thread LEDStart = new Thread(LEDON); //Creates a Thread that will call LEDON() LEDStart.Start(); int i; string temp = "*" + textBoxFileName.Text + "*"; string[] AllFiles = Directory.GetFiles(this.textBoxFolderpath.Text, temp, SearchOption.AllDirectories); for (i = 0; i < AllFiles.Length - 1; i++) { progressBar1.Maximum = AllFiles.Length - 1; string[] row = new string[] { Path.GetFileName(AllFiles[i]), AllFiles[i] }; dataGridView1.Rows.Add(row); progressBar1.Increment(1); if (progressBar1.Value == progressBar1.Maximum) { Thread LEDEND = new Thread(LEDOFF); //Creates a Thread that will call LEDOFF() LEDEND.Start(); } } } //Turn On LED private void LEDON() { if (this.led1.InvokeRequired) { this.led1.Invoke(new MethodInvoker(() => LEDON())); return; }