■ SystemEvents 클래스의 SessionSwitch 정적 이벤트를 사용해 잠금 화면 전환시 처리하는 방법을 보여준다.
▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
using Microsoft.Win32; using System; namespace TestProject { /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private ////////////////////////////////////////////////////////////////////// Event #region 시스템 이벤트 세션 전환시 처리하기 - SystemEvents_SessionSwitch(sender, e) /// <summary> /// 시스템 이벤트 세션 전환시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e) { if(e.Reason == SessionSwitchReason.SessionLock) { Console.WriteLine("SESSION LOCKED"); } else if (e.Reason == SessionSwitchReason.SessionUnlock) { Console.WriteLine("SESSION UNLOCKED"); } } #endregion ////////////////////////////////////////////////////////////////////// Function0 #region 프로그램 시작하기 - Main( /// <summary> /// 프로그램 시작하기 /// </summary> private static void Main() { Console.Title = "SystemEvents 클래스 : SessionSwitch 정적 이벤트를 사용해 잠금 화면 전환시 처리하기"; SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; Console.ReadKey(true); } #endregion } } |