Ответ 1
Когда вы обрабатываете событие Microsoft.Win32.SystemEvents.SessionSwitch
(как кажется, что вы уже делаете, чтобы обнаружить выход из системы), проверьте, Reason
SessionSwitchReason
.SessionLock
:
using Microsoft.Win32;
// ...
// Somewhere in your startup, add your event handler:
SystemEvents.SessionSwitch +=
new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
// ...
void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
switch(e.Reason)
{
// ...
case SessionSwitchReason.SessionLock:
// Do whatever you need to do for a lock
// ...
break;
case SessionSwitchReason.SessionUnlock:
// Do whatever you need to do for an unlock
// ...
break;
// ...
}
}