当前位置: 首页>>代码示例>>C#>>正文


C# Timer.Run方法代码示例

本文整理汇总了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));
    }
开发者ID:joethinh,项目名称:nohros-must,代码行数:31,代码来源:TimerTests.cs

示例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");
    }
开发者ID:joethinh,项目名称:nohros-must,代码行数:14,代码来源:TimerTests.cs

示例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));
    }
开发者ID:joethinh,项目名称:nohros-must,代码行数:22,代码来源:TimerTests.cs

示例4: Main

 internal static void Main(string[] args)
 {
     Timer pesho = new Timer(300);
     pesho.Run();
 }
开发者ID:VyaraGGeorgieva,项目名称:TelerikAcademy,代码行数:5,代码来源:Test.cs


注:本文中的System.Threading.Timer.Run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。