在C#Windows服务中重写HandlerEx
在ServiceBase内的C#Windows服务中,有没有办法覆盖默认HandlerEx?我只能找到OnPowerEvent和OnCustomCommand 对于那些想知道我为什么需要这个的人:OnPowerEvent不处理GUID\u LIDSWITCH\u STATE\u更改。OnPowerEvent会激发,但不会指示盖子是否已关闭或打开 这是我的密码:在C#Windows服务中重写HandlerEx,c#,service,overriding,C#,Service,Overriding,在ServiceBase内的C#Windows服务中,有没有办法覆盖默认HandlerEx?我只能找到OnPowerEvent和OnCustomCommand 对于那些想知道我为什么需要这个的人:OnPowerEvent不处理GUID\u LIDSWITCH\u STATE\u更改。OnPowerEvent会激发,但不会指示盖子是否已关闭或打开 这是我的密码: using System; using System.Runtime.InteropServices; using System.Ser
using System;
using System.Runtime.InteropServices;
using System.ServiceProcess;
namespace KeefService
{
public partial class Main : ServiceBase
{
[DllImport("user32.dll")]
static extern bool BlockInput(bool fBlockIt);
[DllImport("User32.dll")]
static extern IntPtr RegisterPowerSettingNotification(IntPtr hRecipient, ref Guid PowerSettingGuid, Int32 Flags);
static Guid GUID_LIDSWITCH_STATE_CHANGE = new Guid(0xBA3E0F4D, 0xB817, 0x4094, 0xA2, 0xD1, 0xD5, 0x63, 0x79, 0xE6, 0xA0, 0xF3);
const int DEVICE_NOTIFY_SERVICE_HANDLE = 0x00000001;
const int PBT_POWERSETTINGCHANGE = 0x8013;
public Main()
{
InitializeComponent();
}
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
{
if ((int)powerStatus == PBT_POWERSETTINGCHANGE)
BlockInput(true); //TRUE OR FALSE!?!
return base.OnPowerEvent(powerStatus);
}
protected override void OnStart(string[] args)
{
RegisterPowerSettingNotification(this.ServiceHandle, ref GUID_LIDSWITCH_STATE_CHANGE, DEVICE_NOTIFY_SERVICE_HANDLE);
}
protected override void OnStop()
{
BlockInput(false);
}
}
}