private void InitThread(Time time, Exp action) { while (true) { Thread.Sleep(GetTimeUntilSleep(time)); action.Invoke(); } }
public void Schedule(Exp exp, Time time) { actions.Add(exp); Thread t = new Thread(new ThreadStart(() => { InitThread(time, exp); })); workers.Add(t); t.Start(); }
private TimeSpan GetTimeUntilSleep(Time time) { DateTime execDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, time.Hours, time.Minutes, time.Seconds); if (DateTime.Now > execDate) execDate = execDate.AddDays(1); TimeSpan result = execDate - DateTime.Now; return result; }