private int GetSleepTime(int hour, int min, int second){ var now = DateTime.Now; int sleep = (((hour - now.Hour) * 60 + (min - now.Minute)) * 60 + (second - now.Second)) * 1000; if (sleep < 0){ sleep += 24 * 3600 * 1000; } return sleep; }