Well in my classic ASP days I would set a Date variable at the beginning and one at the end and find the difference between the two. However, .NET has this nice little feature in the SSystem.Diagnostics assembly that is called "Stopwatch". Once you instantiate the stopwatch you need to call the Start method at the beginning of your code and the Stop method at the end of your code. From there all you need to do is call for the Elapsed property and it will give you back a TimeSpan. So much easier than trying to calculate the difference between two dates.
Dim sw As New System.Diagnostics.Stopwatch sw.Start() '... Do some long code stuff here ... sw.Stop() Dim ts As TimeSpan = sw.Elapsed lblErrorMessages.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", sw.Elapsed.Hours, sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.Milliseconds / 10)
No comments:
Post a Comment