Is there a Task based replacement for System.Threading.Timer?

前端 未结 7 910
日久生厌
日久生厌 2020-11-27 09:49

I\'m new to .Net 4.0\'s Tasks and I wasn\'t able to find what I thought would be a Task based replacement or implementation of a Timer, e.g. a periodic Task. Is there such a

相关标签:
7条回答
  • 2020-11-27 10:19
    static class Helper
    {
        public async static Task ExecuteInterval(Action execute, int millisecond, IWorker worker)
        {
            while (worker.Worked)
            {
                execute();
    
                await Task.Delay(millisecond);
            }
        }
    }
    
    
    interface IWorker
    {
        bool Worked { get; }
    }
    

    Simple...

    0 讨论(0)
提交回复
热议问题