vb.net关闭计算机休眠,暂时停止VB.Net中的屏幕保护程序和休眠

'''

''' Simple power manager class that enables applications to inform the system

''' that it is in use, thereby preventing the system from entering the sleeping

''' power state or turning off the display while the application is running.

'''

Public Class PowerManager

#Region " Private Sub New "

Private Sub New()

'keep compiler from creating default constructor to create utility class

End Sub

#End Region

'''

''' Enables applications to inform the system that it is in use, thereby preventing the system from entering the sleeping power state or turning off the display while the application is running.

'''

''' The thread's execution requirements. This parameter can be one or more of the EXECUTION_STATE values.

'''

''' If the function succeeds, the return value is the previous thread execution state, as a EXECUTION_STATE value.

''' If the function fails, the return value is NULL.

'''

'''

''' This function does not stop the screen saver from executing.

''' http://msdn.microsoft.com/en-us/library/aa373208.aspx

'''

Private Declare Function SetThreadExecutionState Lib "kernel32" (ByVal esFlags As EXECUTION_STATE) As EXECUTION_STATE

Public Enum EXECUTION_STATE As Integer

'''

''' Informs the system that the state being set should remain in effect until the next call that uses ES_CONTINUOUS and one of the other state flags is cleared.

'''

ES_CONTINUOUS = &H80000000

'''

''' Forces the display to be on by resetting the display idle timer.

'''

ES_DISPLAY_REQUIRED = &H2

'''

''' Forces the system to be in the working state by resetting the system idle timer.

'''

ES_SYSTEM_REQUIRED = &H1

End Enum

Public Shared Function PowerSaveOff() As EXECUTION_STATE

Return SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED Or EXECUTION_STATE.ES_DISPLAY_REQUIRED Or EXECUTION_STATE.ES_CONTINUOUS)

End Function

Public Shared Function PowerSaveOn() As EXECUTION_STATE

Return SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS)

End Function

End Class

Public Class Form1

Private _cancel As Boolean

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

'set system standby to one minute

_cancel = False

PowerManager.PowerSaveOff()

Do Until _cancel

My.Application.DoEvents()

Loop

PowerManager.PowerSaveOn()

'do not forget to restore your power settings

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

_cancel = True

End Sub

End Class

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值