private static void ScheduleJobs() { _timer.Change(Timeout.Infinite, Timeout.Infinite); _schedules.Sort(); if (!_schedules.Any()) { return; } var firstJob = _schedules.First(); if (firstJob.NextRun <= Now) { RunJob(firstJob); if (firstJob.CalculateNextRun == null) { // probably a ToRunNow().DelayFor() job, there's no CalculateNextRun } else { firstJob.NextRun = firstJob.CalculateNextRun(Now.AddMilliseconds(1)); } if (firstJob.NextRun <= Now || firstJob.PendingRunOnce) { _schedules.Remove(firstJob); } firstJob.PendingRunOnce = false; ScheduleJobs(); return; } var interval = firstJob.NextRun - Now; if (interval <= TimeSpan.Zero) { ScheduleJobs(); return; } else { if (interval.TotalMilliseconds > _maxTimerInterval) { interval = TimeSpan.FromMilliseconds(_maxTimerInterval); } _timer.Change(interval, interval); } }
public async Task OnHeartBeatMessageReceived_ShouldReturnElapsedTime() { Now = DateTimeOffset.UtcNow; var client = GetConnectedClient(); _fakeTransportFactory.LastCreatedTransport.SendAction = async message => { Now = Now.AddMilliseconds(100); if (message.Original.Action == ProtocolMessage.MessageAction.Heartbeat) { await Task.Delay(1); await client.FakeProtocolMessageReceived(new ProtocolMessage(ProtocolMessage.MessageAction.Heartbeat)); } }; var result = await client.Connection.PingAsync(); result.IsSuccess.Should().BeTrue(); // Because the now object is static when executed in parallel with other tests the results are affected result.Value.Value.Should().BeGreaterThan(TimeSpan.FromMilliseconds(0)); }
public double GetFurMsFromMs(double timestamp) { return((Now.AddMilliseconds(timestamp) - baseTime).TotalMilliseconds - timeZoneMils); }
public DateTime GetFurTimeFromMs(double timestamp) { return(Now.AddMilliseconds(timestamp)); }