public Task WaitAsync(long time) { TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = TimeHelper.Now() + time, tcs = tcs }; this.timers[timer.Id] = timer; this.timeId.Add(timer.Time, timer.Id); if (timer.Time < this.minTime) { this.minTime = timer.Time; } return(tcs.Task); }
public Task WaitTillAsync(long tillTime, CancellationToken cancellationToken) { TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs }; this.timers[timer.Id] = timer; this.timeId.Add(timer.Time, timer.Id); if (timer.Time < this.minTime) { this.minTime = timer.Time; } cancellationToken.Register(() => { this.Remove(timer.Id); }); return(tcs.Task); }
protected Object() { this.id = IdGenerater.GenerateId(); }