Inheritance: ComInterfaces._Window
 public WindowContext(RemoteSession session)
     : base() {
     _session = session;
     _currentWindow = new Window(session, this, null);
     _previousWindow = _currentWindow;
     _cachedWindows = new List(10);
     _cachedWindows.Add(_currentWindow);
 }
        /// <summary>
        /// Change focus to another window.
        /// </summary>
        /// <param name="title">The name of the window</param>
        /// <param name="timeout"></param>
        public Window SwitchToWindowByTitle(string title, int timeout = -1) {
            var endTime = _session.GetEndTime(timeout);
            while (true) {
                List windows, handles;
                this.ListWindows(out windows, out handles);
                foreach (Window win in windows) {
                    if (win.Handle == _currentWindow.Handle)
                        continue;
                    WindowContext.ActivateWindow(_session, win.Handle);
                    string winTitle = GetCurrentTitle(_session);
                    if (winTitle == title) {
                        _previousWindow = _currentWindow;
                        _currentWindow = win;
                        return win;
                    }
                }

                if (DateTime.UtcNow > endTime)
                    throw new Errors.NoSuchWindowError(title);

                SysWaiter.Wait();
            }
        }
        /// <summary>
        /// Change focus to another window.
        /// </summary>
        /// <param name="name">The name of the window</param>
        /// <param name="timeout"></param>
        public Window SwitchToWindowByName(string name, int timeout = -1) {
            var endTime = _session.GetEndTime(timeout);
            while (true) {
                try {
                    string handle = WindowContext.ActivateWindow(_session, name);
                    _previousWindow = _currentWindow;
                    foreach (Window win in _cachedWindows) {
                        if (win.Handle == handle) {
                            _currentWindow = win;
                            return _currentWindow;
                        }
                    }
                    _currentWindow = new Window(_session, this, null);
                    _cachedWindows.Add(_currentWindow);
                    return _currentWindow;
                } catch (Errors.NoSuchWindowError) { }

                if (DateTime.UtcNow > endTime)
                    throw new Errors.NoSuchWindowError(name);

                SysWaiter.Wait();
            }
        }
 internal Window ActivateWindow(Window window) {
     if (_currentWindow != window) {
         ActivateWindow(_session, window.Handle);
         _previousWindow = _currentWindow;
         _currentWindow = window;
     }
     return window;
 }