private void UpdateInformation(object sender, ElapsedEventArgs e)
        {
            foreach (string hostname in data.Keys.ToArray())
            {
                if (toRemove.Contains(hostname.ToUpper()))
                {
                    data.Remove(hostname.ToUpper());
                    toRemove.Remove(hostname.ToUpper());
                    continue;
                }

                BatteryInfoRequester requester = new BatteryInfoRequester(hostname.ToUpper());
                lock (this.data)
                {
                    Reset(hostname.ToUpper());
                    requester.Start();

                    while (!requester.IsDone)
                    {
                        Thread.Sleep(10);
                    }

                    requester.Stop();
                }

                listeners.Where(x => x.Key == hostname.ToUpper()).Select(y => y.Value).FirstOrDefault()?.ForEach(f => f.PushInformation());
            }
        }
Example #2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            requester = new BatteryInfoRequester(textBox1.Text);
            requester.Start();

            backgroundWorker1.ReportProgress(0);

            while (!requester.IsDone)
            {
                Thread.Sleep(10);
            }

            if (requester.NotFound)
            {
                backgroundWorker1.ReportProgress(1);
            }
            else
            {
                backgroundWorker1.ReportProgress(100);
            }
        }