private ThreadStart tStart; //A reference to tStart thread of BuildIndex public Form1() { InitializeComponent(); index = new Indexing(); //initialize the Indexing class tStart = new ThreadStart(BuildIndex); //start thread for BuildIndex thread = new Thread(tStart); //instantiate a thread }
//Code for when the refresh inverted index button is clicked private void invertedIndex2_Click(object sender, EventArgs e) { index = new Indexing(); { if (thread.IsAlive) { MessageBox.Show("The index is currently busy. Please try again later"); //message shown if index building is in progress } else { thread = new Thread(tStart); // re-instantiates the thread if it already exists thread.Start(); // calls buildIndex on a new Thread } } }