async Task LotteryThread() { TimeSpan time = (lottery.dueDate - DateTime.UtcNow); int sleepTime = (int)time.TotalMilliseconds; int extraSleepTime = Verify.Min((int)(time.TotalMilliseconds - sleepTime), 0); RestUserMessage[] msgs = null; if (sleepTime > 0) { Log.LogS($"Next Lottery in {Math.Floor(time.TotalDays)}Days" + $" {time.ToString("h'h 'm'm 's's'")}"); await Task.Delay(sleepTime); await Task.Delay(extraSleepTime); } while (lottery.entries.Count < 3) { lottery.daysLength++; lottery.dueDate = lottery.dueDate.AddDays(lottery.daysLength); lottery.baseValue += lottery.daysLength * 10; lottery.Save(); if (msgs != null) { foreach (var m in msgs) { await m.DeleteAsync(); } } msgs = await lottery.Notify("Lottery time extended, more participants required!"); time = (lottery.dueDate - DateTime.UtcNow); sleepTime = (int)time.TotalMilliseconds; extraSleepTime = Verify.Min((int)(time.TotalMilliseconds - sleepTime), 0); if (sleepTime > 0) { Log.LogS($"Lottery extended to {Math.Floor(time.TotalDays)}Days {time.ToString("h'h 'm'm 's's'")}"); await Task.Delay(sleepTime); } await Task.Delay(5); } await lottery.End(); lottery = new Lottery(Program.rng.Next(1, 51) * 10, Program.rng.Next(3, 14)); }