Link to home
Start Free TrialLog in
Avatar of zell71
zell71Flag for United Kingdom of Great Britain and Northern Ireland

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
SOLUTION
Avatar of Bruce_1975
Bruce_1975

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zell71

ASKER

gave more points to CuteBug as thats the answer i used, cheers
Avatar of zell71

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;
        }

Open in new window