/// <summary> /// Start the session, if possible. /// </summary> private void HandleSessionStart() { // Check if the KCD has already sent us the end session event. if (SessionIDTree.ContainsKey(SessionID)) { HandleSessionTrouble(new Exception("the KCD closed the connection unexpectedly")); return; } // Clear the session ID tree. SessionIDTree.Clear(); // Show the overlay window. Overlay = new RunningOverlay(); Overlay.Relink(this); // Configure the inactivity monitor to timeout about 10 minutes. InactivityMonitor = MonitorCreator.CreateInstance(MonitorType.GlobalHookMonitor); InactivityMonitor.MonitorKeyboardEvents = true; InactivityMonitor.MonitorMouseEvents = true; InactivityMonitor.Interval = 600000; InactivityMonitor.Elapsed += delegate(Object sender, ElapsedEventArgs args) { KBase.ExecInUI(OnInactivity); }; InactivityMonitor.Enabled = true; // Start the session. Status = VncSessionStatus.Started; // Notify listeners. PostLocalVncSessionEvent(true, null); Kws.OnStateChange(WmStateChange.Transient); }
/// <summary> /// Clean up the state when the session has completed to avoid resource /// leaks. This object CANNOT be reused for another session since some /// recently cancelled threads may still reference the object and try /// to modify its state. /// </summary> private void Terminate() { Status = VncSessionStatus.Completed; AppVnc.SessionPresentFlag = false; App.LocalSession = null; if (Overlay != null) { Overlay.Terminate(); Overlay = null; } if (TicketQuery != null) { TicketQuery.Terminate(); TicketQuery = null; } if (Tunnel != null) { Tunnel.Terminate(); Tunnel = null; } if (TunnelThread != null) { TunnelThread.RequestCancellation(); TunnelThread = null; } if (MainProcess != null) { MainProcess.Terminate(); MainProcess = null; } if (DummyProcess != null) { DummyProcess.Terminate(); DummyProcess = null; } if (Timer != null) { Timer.WakeMeUp(-1); Timer = null; } if (InactivityMonitor != null) { InactivityMonitor.Enabled = false; InactivityMonitor.Dispose(); InactivityMonitor = null; } }