zell71
asked on
Timer Function Question
how can i use a timer to count how long it takes to return search data?
i.e MessageBox.Show ("Your search took XXX seconds/minutes to return data", Timer1)
?how do i implement this?
cheers
i.e MessageBox.Show ("Your search took XXX seconds/minutes to return data", Timer1)
?how do i implement this?
cheers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is the full coded using answers above, cheers
private void ShowDateSystemLogErrors_Click(object sender, EventArgs e)
{
DateTime dt = dateTimePicker1.Value;
// Change to hourglass whilst working
this.Cursor = Cursors.WaitCursor;
try
{
Stopwatch stopwatch = new Stopwatch();
// start the stopwatch
stopwatch.Start();
// Complete the search and return a list
this.SystemLogErrorsView.DataSource = this._Errors.GetByDate(dt);
// stop the stopwatch
stopwatch.Stop();
// Get the elapsed time as a TimeSpan value
TimeSpan ts = stopwatch.Elapsed;
// Timewatch string formatting
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds / 10);
MessageBox.Show(string.Format("The Search Took {0} to Complete", elapsedTime));
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
// Change back to arrow cursor
this.Cursor = Cursors.Default;
}
ASKER