예제 #1
0
 public void BatteryCheck()
 {
     while (true)
     {
         string a   = new Battery.PowerStatus().PowerLineStatus.ToString();
         int    num = (int)(SystemInformation.PowerStatus.BatteryLifePercent * 100f);
         if (a != "Online")
         {
             Stop = 1;
             if (MessageBox.Show("This process requires power to avoid an accident power-off during an update." + Environment.NewLine + "Connect the AC adapter to the system.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand).ToString() != "OK")
             {
                 Stop = 1;
                 tbtoff();
                 Environment.Exit(21);
             }
             Stop = 1;
         }
         else if (num < 25)
         {
             Stop = 1;
             if (MessageBox.Show("This process requires power to avoid an accident power-off during an update." + Environment.NewLine + "Connect the AC adapter to the system and charge the battery on system over 25%.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand).ToString() != "OK")
             {
                 Stop = 1;
                 tbtoff();
                 Environment.Exit(22);
             }
             Stop = 1;
         }
         else if (a == "Online")
         {
             Stop = 0;
         }
     }
 }
예제 #2
0
        private void Start_Click(object sender, EventArgs e)
        {
            String      batterystatus;
            PowerStatus pwr = SystemInformation.PowerStatus;

            batterystatus = SystemInformation.PowerStatus.BatteryChargeStatus.ToString();
            String batterylife;

            batterylife = SystemInformation.PowerStatus.BatteryLifePercent.ToString();
            B           = Convert.ToDouble(batterylife);
            B           = B * 100;
            Console.WriteLine(B);
            label1.Text = "Battery level : " + B.ToString() + "%  Battery Status: " + batterystatus;
            if (B == l)
            {
                SoundPlayer player = new SoundPlayer();
                player.SoundLocation = "C:\\example\\Sample1.wav";
                player.PlayLooping();
                timer1.Enabled = false;
                //player.Play();
            }
        }