public void UpdateDisplay(DeviceInfo info) { if (lblTitle.InvokeRequired) { lblTitle.Invoke(new Action( delegate() { UpdateDisplay(info); } )); } else { if (info.DeviceConnected) { lblTitle.Text = "Battery Stats (" + info.Model + ")"; lblACPower.Text = info.ACPower ? "Yes" : "No"; lblUSBPower.Text = info.USBPower ? "Yes" : "No"; lblLevel.Text = info.PowerLevel.ToString() + "%"; lblLastChecked.Text = info.LastCheckedTimestamp; } else { lblTitle.Text = "Battery Stats (No Device)"; lblACPower.Text = "--"; lblUSBPower.Text = "--"; lblLevel.Text = "--"; lblLastChecked.Text = info.LastCheckedTimestamp; } } }
public DevicePoller(IDisplayReceiver recv) { _receiver = recv; _info = new DeviceInfo(); _pollingTimer = new System.Threading.Timer(new System.Threading.TimerCallback(PollingIntervalElapsed), null, 0, PollingInterval); _regexMapping = new Dictionary<Regex, KeyValuePair<string, Type>>() { { _rePowerLevel, new KeyValuePair<string, Type>("PowerLevel", typeof(int))}, { _reACPower, new KeyValuePair<string, Type>("ACPower", typeof(bool)) }, { _reUSBPower, new KeyValuePair<string, Type>("USBPower", typeof(bool)) } }; }