144 lines
5.0 KiB
C#
144 lines
5.0 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace System.Diagnostics
|
|
{
|
|
/// <summary>Provides a set of methods and properties that you can use to accurately measure elapsed time.</summary>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x020000F4 RID: 244
|
|
public class Stopwatch
|
|
{
|
|
/// <summary>Gets the current number of ticks in the timer mechanism.</summary>
|
|
/// <returns>A long integer representing the tick counter value of the underlying timer mechanism.</returns>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x0600089B RID: 2203
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern long GetTimestamp();
|
|
|
|
/// <summary>Initializes a new <see cref="T:System.Diagnostics.Stopwatch" /> instance, sets the elapsed time property to zero, and starts measuring elapsed time.</summary>
|
|
/// <returns>A <see cref="T:System.Diagnostics.Stopwatch" /> that has just begun measuring elapsed time.</returns>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x0600089C RID: 2204 RVA: 0x00016D2C File Offset: 0x00014F2C
|
|
public static Stopwatch StartNew()
|
|
{
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
stopwatch.Start();
|
|
return stopwatch;
|
|
}
|
|
|
|
/// <summary>Gets the total elapsed time measured by the current instance.</summary>
|
|
/// <returns>A read-only <see cref="T:System.TimeSpan" /> representing the total elapsed time measured by the current instance.</returns>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x17000245 RID: 581
|
|
// (get) Token: 0x0600089D RID: 2205 RVA: 0x00016D48 File Offset: 0x00014F48
|
|
public TimeSpan Elapsed
|
|
{
|
|
get
|
|
{
|
|
if (Stopwatch.IsHighResolution)
|
|
{
|
|
return TimeSpan.FromTicks(this.ElapsedTicks / (Stopwatch.Frequency / 10000000L));
|
|
}
|
|
return TimeSpan.FromTicks(this.ElapsedTicks);
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the total elapsed time measured by the current instance, in milliseconds.</summary>
|
|
/// <returns>A read-only long integer representing the total number of milliseconds measured by the current instance.</returns>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x17000246 RID: 582
|
|
// (get) Token: 0x0600089E RID: 2206 RVA: 0x00016D84 File Offset: 0x00014F84
|
|
public long ElapsedMilliseconds
|
|
{
|
|
get
|
|
{
|
|
if (Stopwatch.IsHighResolution)
|
|
{
|
|
return this.ElapsedTicks / (Stopwatch.Frequency / 1000L);
|
|
}
|
|
return checked((long)this.Elapsed.TotalMilliseconds);
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the total elapsed time measured by the current instance, in timer ticks.</summary>
|
|
/// <returns>A read-only long integer representing the total number of timer ticks measured by the current instance.</returns>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x17000247 RID: 583
|
|
// (get) Token: 0x0600089F RID: 2207 RVA: 0x00016DC0 File Offset: 0x00014FC0
|
|
public long ElapsedTicks
|
|
{
|
|
get
|
|
{
|
|
return (!this.is_running) ? this.elapsed : (Stopwatch.GetTimestamp() - this.started + this.elapsed);
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets a value indicating whether the <see cref="T:System.Diagnostics.Stopwatch" /> timer is running.</summary>
|
|
/// <returns>true if the <see cref="T:System.Diagnostics.Stopwatch" /> instance is currently running and measuring elapsed time for an interval; otherwise, false.</returns>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x17000248 RID: 584
|
|
// (get) Token: 0x060008A0 RID: 2208 RVA: 0x00016DEC File Offset: 0x00014FEC
|
|
public bool IsRunning
|
|
{
|
|
get
|
|
{
|
|
return this.is_running;
|
|
}
|
|
}
|
|
|
|
/// <summary>Stops time interval measurement and resets the elapsed time to zero.</summary>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x060008A1 RID: 2209 RVA: 0x00016DF4 File Offset: 0x00014FF4
|
|
public void Reset()
|
|
{
|
|
this.elapsed = 0L;
|
|
this.is_running = false;
|
|
}
|
|
|
|
/// <summary>Starts, or resumes, measuring elapsed time for an interval.</summary>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x060008A2 RID: 2210 RVA: 0x00016E08 File Offset: 0x00015008
|
|
public void Start()
|
|
{
|
|
if (this.is_running)
|
|
{
|
|
return;
|
|
}
|
|
this.started = Stopwatch.GetTimestamp();
|
|
this.is_running = true;
|
|
}
|
|
|
|
/// <summary>Stops measuring elapsed time for an interval.</summary>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x060008A3 RID: 2211 RVA: 0x00016E28 File Offset: 0x00015028
|
|
public void Stop()
|
|
{
|
|
if (!this.is_running)
|
|
{
|
|
return;
|
|
}
|
|
this.elapsed += Stopwatch.GetTimestamp() - this.started;
|
|
this.is_running = false;
|
|
}
|
|
|
|
/// <summary>Gets the frequency of the timer as the number of ticks per second. This field is read-only.</summary>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x040002B6 RID: 694
|
|
public static readonly long Frequency = 10000000L;
|
|
|
|
/// <summary>Indicates whether the timer is based on a high-resolution performance counter. This field is read-only.</summary>
|
|
/// <filterpriority>1</filterpriority>
|
|
// Token: 0x040002B7 RID: 695
|
|
public static readonly bool IsHighResolution = true;
|
|
|
|
// Token: 0x040002B8 RID: 696
|
|
private long elapsed;
|
|
|
|
// Token: 0x040002B9 RID: 697
|
|
private long started;
|
|
|
|
// Token: 0x040002BA RID: 698
|
|
private bool is_running;
|
|
}
|
|
}
|