static void Main(string[] args) { CommandLineArgs parsedArgs = new CommandLineArgs(); bool ok = CommandLine.Parser.Default.ParseArguments(args, parsedArgs); if (!ok) { HelpText help = HelpText.AutoBuild(parsedArgs); throw new Exception(string.Format("Invalid command line args: {0}", help.ToString())); } if (parsedArgs.TopOfHour) { //wait until the top of the hour to start TimeSpan ts = TimeUntilNextHour(); Console.WriteLine("waiting for " + ts); Thread.Sleep(ts); } MainService service = GetService(parsedArgs.Username, parsedArgs.Password); PreCacher cacher = new PreCacher(service); while (true) { //cache the last hour of changes DateTime now = DateTime.Now; DateTime start = GetDateTimeToHour(now.AddHours(-1)); DateTime end = GetDateTimeToHour(now); cacher.CacheData(parsedArgs.VendorID, parsedArgs.JobID, start, end); //wait until the top of the next hour Thread.Sleep(TimeUntilNextHour()); //Thread.Sleep(parsedArgs.RepeatMin * 60 * 1000); } }