søndag 26. april 2009

count time..

//get actual time
DateTime startTime = DateTime.Now;

// do something

// get difference as time span
TimeSpan span = DateTime.Now.Subtract(startTime);
// create message box
MessageBox.Show(string.Format("The operation took {0} seconds", span.TotalSeconds));
.------------------------------.
using System;
using System.Diagnostics;

static void Main(string[] args)
{
StopWatch s = new StopWatch();

// Start the stopwatch
s.Start();

// Call your search method here
MySearch();

// Stop the stopwatch
s.Stop();

// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;

MessageBox.Show ("Your search took {0} seconds to return data", ts.TotalSeconds );

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

Ingen kommentarer:

Legg inn en kommentar