Thursday, 19 November 2009

While you are away...

Couple of days ago I wrote one tool which should check if computer was locked and I found a very simple solution. It was enough to handle SessionSwitch event of SystemEvents class from Microsoft.Win32 namespace.


SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
...
void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
        switch (e.Reason)
        {
                case SessionSwitchReason.SessionLock:
                //computer locked
                case SessionSwitchReason.SessionUnlock:
                //computer unlocked
           }
}


It can be used in a wide variety of cases, as an example you can start downloading an update or something else or maybe start some calculations and so on.

No comments:

Post a Comment