示例#1
0
        private void updatetimer_Tick(object sender, EventArgs e)
        {
            bool windowopen;

            using (WebClient wc = new WebClient())
            {
                string   newURL  = Form1.jsonURL;
                var      newjson = string.Empty;
                frmPopup frmpop  = new frmPopup();
                try
                {
                    newjson    = wc.DownloadString(newURL.ToString());
                    windowopen = FormIsOpen(Application.OpenForms, typeof(frmPopup));
                }
                catch (WebException ex)
                {
                    windowopen = FormIsOpen(Application.OpenForms, typeof(frmPopup));
                    if (windowopen == false)
                    {
                        frmpop.Show();
                    }
                    Console.WriteLine($"{ex}");
                }

                if (windowopen)
                {
                    frmpop.Hide();
                }

                var newlist = (JsonConvert.DeserializeObject <List <JSONModel> >(newjson));
                if (newlist != null)
                {
                    datalist.AddRange(newlist);
                }
            }

            chart1.DataBind();
            processTick();
        }
示例#2
0
        private void initdataload()
        {
            using (WebClient wc = new WebClient())
            {
                string URL        = Form1.jsonURL + "=360";
                var    json       = string.Empty;
                bool   initialtry = true;

                while (initialtry)
                {
                    try
                    {
                        json       = wc.DownloadString(URL.ToString());
                        initialtry = false;
                    }
                    catch (WebException e)
                    {
                        bool windowopen = FormIsOpen(Application.OpenForms, typeof(frmPopup));
                        if (!windowopen)
                        {
                            frmPopup frmpop = new frmPopup();
                            frmpop.ShowDialog();
                        }
                        Console.WriteLine($"{e}");
                    }
                }

                datalist = JsonConvert.DeserializeObject <List <JSONModel> >(json);

                chart1.DataSource = datalist;
                chart1_settings();

                processTick();

                updatetimer.Interval = 5500;
                updatetimer.Start();
            }
        }