42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Threading;
|
|
using System.Diagnostics;
|
|
|
|
namespace Threding_Demo2
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
long frequency = Stopwatch.Frequency;
|
|
Console.WriteLine("Timer frequency in ticks per second = {0}",frequency);
|
|
long nanosecPerTick = (1000L * 1000L * 1000L) / frequency;
|
|
Console.WriteLine("Timer is accurate within {0} nanoseconds",nanosecPerTick);
|
|
}
|
|
}
|
|
class demo
|
|
{
|
|
public Stopwatch Stopwatcher { get; set; }
|
|
public demo()
|
|
{
|
|
this.Stopwatcher = new Stopwatch();
|
|
}
|
|
public void PreSpin(Stopwatch a, double duration)
|
|
{
|
|
var current = a.ElapsedTicks;
|
|
while ((a.ElapsedTicks-current)<duration )
|
|
{
|
|
Thread.SpinWait(10);
|
|
}
|
|
}
|
|
public void Spin(Stopwatch a, double duration)
|
|
{
|
|
this.PreSpin(a,duration);
|
|
}
|
|
}
|
|
}
|