WaitForInputIdle() public method

public WaitForInputIdle ( int milliseconds ) : bool
milliseconds int
return bool
Example #1
0
        /// <summary>
        ///     The Startup handler.
        /// </summary>
        /// <param name="e">The event arguments</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            // Start the WindowMove client.
            CreateWindow();

            try
            {
                // Obtain an AutomationElement from the target window handle.
                _targetWindow = StartTargetApp(_targetApplication);

                // Does the automation element exist?
                if (_targetWindow == null)
                {
                    Feedback("No target.");
                    return;
                }
                Feedback("Found target.");

                // find current location of our window
                _targetLocation = _targetWindow.Current.BoundingRectangle.Location;

                // Obtain required control patterns from our automation element
                _windowPattern = GetControlPattern(_targetWindow,
                    WindowPattern.Pattern) as WindowPattern;

                if (_windowPattern == null) return;

                // Make sure our window is usable.
                // WaitForInputIdle will return before the specified time 
                // if the window is ready.
                if (false == _windowPattern.WaitForInputIdle(10000))
                {
                    Feedback("Object not responding in a timely manner.");
                    return;
                }
                Feedback("Window ready for user interaction");

                // Register for required events
                RegisterForEvents(
                    _targetWindow, WindowPattern.Pattern, TreeScope.Element);

                // Obtain required control patterns from our automation element
                _transformPattern =
                    GetControlPattern(_targetWindow, TransformPattern.Pattern)
                        as TransformPattern;

                if (_transformPattern == null) return;

                // Is the TransformPattern object moveable?
                if (_transformPattern.Current.CanMove)
                {
                    // Enable our WindowMove fields
                    _xCoordinate.IsEnabled = true;
                    _yCoordinate.IsEnabled = true;
                    _moveTarget.IsEnabled = true;

                    // Move element
                    _transformPattern.Move(0, 0);
                }
                else
                {
                    Feedback("Wndow is not moveable.");
                }
            }
            catch (ElementNotAvailableException)
            {
                Feedback("Client window no longer available.");
            }
            catch (InvalidOperationException)
            {
                Feedback("Client window cannot be moved.");
            }
            catch (Exception exc)
            {
                Feedback(exc.ToString());
            }
        }