none
Resolution of timer定时器 RRS feed

  • 问题

  • 请问,System.timers.timer和threading.timer 可以实现25-30 ms左右精度的定时吗? 

    最好能提供一个例程.

    2013年6月18日 1:00

答案

  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Threading;
    using System.Diagnostics;
     
    namespace CSharp
    {
        class Program
        {
            static void Main(string[] args)
            {
                Stopwatch watch = new Stopwatch();
                Console.WriteLine("开始计时……");
                watch.Start();
                Timer t = new System.Threading.Timer(
                    (state=>
                    {
                        watch.Stop();
                        Console.WriteLine(watch.ElapsedMilliseconds);
                        watch.Restart();
                    }, null0,25);
                Console.Read();
            }
        }
     
    }

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年6月18日 6:11
    版主