本文整理汇总了C#中System.Threading.Timer.Run方法的典型用法代码示例。如果您正苦于以下问题:C# Timer.Run方法的具体用法?C# Timer.Run怎么用?C# Timer.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Timer
的用法示例。
在下文中一共展示了Timer.Run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldTimeSeriesOfEvents
public void ShouldTimeSeriesOfEvents() {
var signaler = new ManualResetEvent(false);
var timer = new Timer();
long count = 0;
var snapshot = new Snapshot(new long[0]);
timer.Update(10);
timer.Update(20);
timer.Update(20);
timer.Update(30);
timer.Update(40);
timer.GetCount((x, context) => {
count = x;
});
timer.GetSnapshot((x, timestamp) => snapshot = x);
timer.Run(() => signaler.Set());
signaler.WaitOne();
Assert.That(count, Is.EqualTo(5));
Assert.That(snapshot.Max, Is.InRange(40, 40.0001));
Assert.That(snapshot.Min, Is.InRange(10, 10.0001));
Assert.That(snapshot.Mean, Is.InRange(24, 24.0001));
Assert.That(snapshot.StdDev, Is.InRange(11.401, 11.402));
Assert.That(snapshot.Median, Is.InRange(20, 20.0001));
Assert.That(snapshot[0.75], Is.InRange(35, 35.0001));
Assert.That(snapshot[0.99], Is.InRange(40, 40.0001));
Assert.That(snapshot.Values, Is.EqualTo(new double[] {10, 20, 20, 30, 40}));
Assert.That(snapshot.Size, Is.EqualTo(5));
}
示例2: ShouldTimeThroughContext
public void ShouldTimeThroughContext() {
var signaler = new ManualResetEvent(false);
var timer = new Timer();
var snapshot = new Snapshot(new long[0]);
long count = 0;
timer.Time().Stop();
timer.GetCount((x, context) => count = x);
timer.Run(() => signaler.Set());
signaler.WaitOne();
Assert.That(count, Is.EqualTo(1), "the timer has count of 1");
}
示例3: ShouldCreateEmptyTimer
public void ShouldCreateEmptyTimer() {
var signaler = new ManualResetEvent(false);
var timer = new Timer(new ClockMock());
long count = 0;
var snapshot = new Snapshot(new long[0]);
timer.GetCount((x, context) => count = x);
timer.GetSnapshot((x, timestamp) => snapshot = x);
timer.Run(() => signaler.Set());
signaler.WaitOne();
Assert.That(count, Is.EqualTo(0));
Assert.That(snapshot.Max, Is.InRange(0, 0.0001));
Assert.That(snapshot.Min, Is.InRange(0, 0.0001));
Assert.That(snapshot.Mean, Is.InRange(0, 0.0001));
Assert.That(snapshot.StdDev, Is.InRange(0, 0.0001));
Assert.That(snapshot.Median, Is.InRange(0, 0.0001));
Assert.That(snapshot[0.75], Is.InRange(0, 0.0001));
Assert.That(snapshot[0.99], Is.InRange(0, 0.0001));
Assert.That(snapshot.Size, Is.EqualTo(0));
}
示例4: Main
internal static void Main(string[] args)
{
Timer pesho = new Timer(300);
pesho.Run();
}