/*TODO: Threads execution time needs to be synchronized so that we can accurately project. * select max(ModifiedAtUtcTimeStamp) - min(ModifiedAtUtcTimeStamp) from Position where IsActive = 1 * Right now seeing a differential of about 55 seconds. * One potential solution here would be to have app running on multiple machines, * and each app responsible for a range of flights or faster machine. CPU and IO are pegged. */ public void Run() { //do //{ System.Console.WriteLine("Getting aircraft list."); List <AircraftCore> aircraftList = null; int page = 0; int pageSize = Int32.Parse(ConfigurationManager.AppSettings["aircraftPerThread"]); do { aircraftList = _aircraftRepository.Search(e => e.IsActive == true, page, pageSize).ToList(); if (aircraftList.Count() > 0) { var tempAircraftList = aircraftList; ThreadStart action = () => { HandlePosition(tempAircraftList); }; Thread thread = new Thread(action, Int32.Parse(ConfigurationManager.AppSettings["threadStackSize"])) { IsBackground = true }; thread.Start(); } page++; } while (aircraftList.Count() == pageSize); System.Console.ReadLine(); //TODO: This logic needs to be revisited. Need to kill the currently running threads to make sure records aren't being processed a second time. // Thread.Sleep(Int32.Parse(ConfigurationManager.AppSettings["handleAircraftTimeInterval"])); //} while (true); }