Chi sviluppa su device basati su Windows CE di tipo industriale sa bene che il controllo del livello della batteria è una dei criticità da affrontare. Purtroppo il .NET CF per Windows CE non offre nessuna classe per il monitoraggio di tale risorsa. Ovviamente il sistema operativo mette a disposizione un set di API apposite per questo problema. Nel codice associato al post trovare una classe C# che si fa carico di gestire queste API. Oltre al codice della classe trovate anche un programma di esempio che ne dimostra l’utilizzo, in dettaglio:
1: private void Form1_Load(object sender, EventArgs e)
2: {
3: PwdManagment = new PowerManagement();
4:
5: PwdManagment.PowerNotify += PwdManagment_PowerNotify;
6: }
1: private void btnStart_Click(object sender, EventArgs e)
2: {
3: PwdManagment.StartNotifications();
4: lblNotification.Text = "StartNotifications...";
5: }
1: private void btnStopNotification_Click(object sender, EventArgs e)
2: {
3: PwdManagment.StopNotifications();
4: lblNotification.Text = "StopNotifications...";
5: }
1:
2: private void PwdManagment_PowerNotify(object sender, EventArgs e)
3: {
4: try
5: {
6: // get power info element
7: //
8: var powerInfo = PwdManagment.GetNextPowerInfo();
9:
10: if ( powerInfo.Message != PowerManagement.MessageTypes.Status )
11: return;
12:
13: this.BeginInvoke(new Action<PowerManagement.PowerInfo>(UpdateLevels), powerInfo);
14: }
15: catch(Exception ex)
16: {
17: MessageBox.Show(ex.ToString());
18: }
19: }
Nessun commento:
Posta un commento