I have two buttons start and stop. On start button's click, i would like to hit a table and loop thro' the records, display the difference of time(time taken) when records are in the loop.
However when the start button is clicked, since the number of records are high, i can't click "stop" button , I am trying to click start button, run that process independently, for example, if 5000 records are processed, when i click stop button, i would like to display the time taken for those 5000 records, again when start is clicked, continue the records where it left off from.
How can i handle two events independently ? Any piece of thoughts would be really helpful.Thanks in advance.
private void startQueries()
{
thread=
new Thread(this.LoadResults);
thread.IsBackground =true;
thread.Start();
}
private void LoadResults()
{
//Method that runs a select query - fetches 1000s of records
Timespan startTime = <<Record the start time>>;
//Loop thro' all the 1000s of records;
Timespan stopTime=<<Record the stop time>>;
//Display the difference between start and stop time.
}
private void btnStart_Click(object sender, EventArgs e)
{
if(thread!=null)
{
if (thread.ThreadState == ThreadState.Running)
{
//do nothing
}
else if (thread.ThreadState == ThreadState.Suspended)
{
startQueries();
}
}
private void btnStop_Click(object sender, EventArgs e)
{
//Stop the running thread
// Need to display the time between the thread start and stop.
}
}