private static void handleHeartBeat(DateTime time, Controller controller, Configuration config, SparkQueue sparkQueue)
        {

            totalRuntimeMilliseconds += getMillisecondsSinceLastHeartBeat(time);
            totalNumberOfCycles++;
            numberOfHeartBeatsSinceLastStateChange++;
            timeOfLastHeartbeat = time;

            TimeSpan ts = time - timeOfLastHeartbeat;

            double totalMillisecondsSinceLastCycle = ts.Ticks / 10000.0;

            if (currentSystemState == SystemState.DOWN &&
            numberOfHeartBeatsSinceLastStateChange >= config.HeartbeatsRequiredToChangeState &&
            totalMillisecondsSinceLastCycle < (config.CycleLengthMs * 2.0))
            {
                setSystemSateToRun(time, config, sparkQueue);
            }

        }
        public MainPage()
        {
            this.InitializeComponent();

            string powerOuttagePost = PowerOuttageHandler.CheckLog().Result;
            SetUpMisc(powerOuttagePost);

            _uiSyncContext = System.Threading.SynchronizationContext.Current;

            DateTime dt = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"));
            txtblockTime.Text = dt.Hour.ToString() + ":" + dt.Minute.ToString(); // ToString("HH:mm:ss");

            timerDateTime = new DispatcherTimer();
            timerDateTime.Interval = TimeSpan.FromMilliseconds(300);
            //timerDateTime.Tick += TimerDateTime_Tick;
            timerDateTime.Tick += TimerDateTime_Tick1;
            timerDateTime.Start();

            setUpSystem();
            setUpBoardIO();


            controller = new Controller();
            configuration = new Configuration();
            powerHandler = new PowerOuttageHandler(configuration);
            network = new Network();

            Utilities.SparkEmail.Send(this.configuration.AssetNumber + " Starting ");


            viewModel = new VM.ViewModel(controller, configuration, cycleLights, network, sparkQueue, this);

            //sparkQueue = new SparkQueue();
            sparkQueue.DataReadyForPickUp += SparkQueue_DataReadyForPickUp;
        }