日期:2014-05-18 浏览次数:21001 次
public class SystemPowerManager
    {
        private Timer tmrGetPowerStatus;
        private SYSTEM_POWER_STATUS_EX2 powStatus;
        public TimerCallback GetPowerStatusCallback;
        public SystemPowerManager()
        {
            GetPowerStatusCallback = GetSystemPowerStatus;
            tmrGetPowerStatus = new Timer(GetPowerStatusCallback, powStatus, 0, 2000);
        }
        private void GetSystemPowerStatus(object status)
        {
            NativeMethods.GetSystemPowerStatusEx2(ref powStatus, (uint)Marshal.SizeOf(powStatus), false);
        }
    }