/// <summary>Constructor - NotifyIcon initializer</summary> /// <param name="notifyIcon"></param> public TimeManager(NotifyIcon notifyIcon) { _notifyIcon = notifyIcon; //initialize user state with unlocked since the program started _userState = new Dictionary <string, SessionSwitchReason> { { StorageFileManager.GetLoginUserName(), SessionSwitchReason.SessionUnlock } }; //Read the configuration Config = StorageFileManager.ReadConfig(); //Clear the log StorageFileManager.Clear(); //create a new timer to go for a number of seconds (1000 milliseconds = 1 second) timer = new System.Timers.Timer(Config.PollingIntervalInSeconds * 1000D); //have the timer start again when it finishes.. (creates an interval timer) timer.AutoReset = true; //Define what to do when the timer goes off - call timer_Elapsed timer.Elapsed += timer_Elapsed; //Start the timer timer.Start(); //capture SystemEvent SessionSwitch SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; }
private SessionSwitchReason GetUserState() { string key = StorageFileManager.GetLoginUserName(); SessionSwitchReason val; if (!_userState.TryGetValue(key, out val)) { _userState.Add(key, SessionSwitchReason.SessionUnlock); val = SessionSwitchReason.SessionUnlock; } return(val); }
private void SetUserState(SessionSwitchReason newState) { string key = StorageFileManager.GetLoginUserName(); SessionSwitchReason val; if (_userState.TryGetValue(key, out val)) { _userState[key] = newState; } else { _userState.Add(key, newState); } }