protected override void OnClosed(EventArgs e)
 {
     running = false;
     data_pull_timer.Enabled = false;
     uiE.CloseDataStream(); //close the data stream connection if the form is closing.
     ConfigurationManager.AppSettings.Set("AccountName", accountName.Text);
     ConfigurationManager.AppSettings.Set("AccountSharedKey", accountKey.Text);
     ConfigurationManager.AppSettings.Set("HomeId", homeID.Text);
     ConfigurationManager.AppSettings.Set("AppId", appID.Text);
     ConfigurationManager.AppSettings.Set("StreamId", streamID.Text);
     base.OnClosed(e);
 }
 private void timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (running)
     {
         // 1. open the datastream
         ExportUI exportUI = new ExportUI();
         exportUI.SetupDataStream(true, accountName.Text, accountKey.Text, homeID.Text, appID.Text, streamID.Text);
         // 2. get latest
         Dictionary <IKey, Tuple <IValue, DateTime> > latestVals = getLatestHelper(exportUI);
         // 3. check rules
         checkRules(latestVals);
         // 4. close datastream
         exportUI.CloseDataStream();
     }
 }