Search code examples
windowsevents.net-corelockingsystem

Handle windows lock/unlock events in .net core


In the .Net Framework there is an event that, when handled, you could log was lock/unlock events on an account. It is this one:

Microsoft.Win32.SystemEvents.SessionSwitch

I can't find this in .Net core. Does anyone know what the equivalent in .Net Core is?


Solution

  • As this event is platform specific, it probably wouldn't the part of .Net Standard, so you can't find it in .Net Core. According the APIs of .Net, they do not have plans for introducing this class.

    So, you may try to create a platform-specific library with SessionSwitch code, but that wouldn't run on other platforms rather than Windows, and put your general logic into .Net Standard library so you can use that either from .Net Core app and .Net Framework app.

    Other way is to use Mono, which contain such events in it.