コード例 #1
0
        public async Task BasicTest()
        {
            int msWait = 1000 - DateTime.Now.TimeOfDay.Milliseconds - 200;

            if (msWait < 0)
            {
                msWait = msWait + 1000;
            }

            await Task.Delay(msWait);

            int count = 0;

            void Action()
            {
                count++;
            }

            using Fiber fiber = new Fiber();
            using (IDisposable sub = fiber.CronSchedule(Action, "0/2 * * 1/1 * ? *"))
            {
                await Task.Delay(TimeSpan.FromSeconds(4.1));
            }

            Assert.IsTrue(count >= 2);

            await Task.Delay(TimeSpan.FromSeconds(8));

            Assert.IsTrue(count <= 3);
        }