Exemple #1
0
        /// <summary>
        /// Updates the status text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="windowWidth">Width of the window.</param>
        private void UpdateStatusText(string text, double windowWidth)
        {
            _currentStatusText  = text;
            _currentWindowWidth = windowWidth;

            if (PleaseWaitWindow == null)
            {
                return;
            }

            Dispatcher.Invoke(() =>
            {
                PleaseWaitWindow.Text     = _currentStatusText;
                PleaseWaitWindow.MinWidth = double.IsNaN(_currentWindowWidth) ? 0d : _currentWindowWidth;
                PleaseWaitWindow.UpdateLayout();
            });
        }
Exemple #2
0
        /// <summary>
        /// Updates the status text.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="windowWidth">
        /// Width of the window.
        /// </param>
        private void UpdateStatusText(string text, double windowWidth)
        {
            _currentStatusText  = text;
            _currentWindowWidth = windowWidth;

            if (PleaseWaitWindow == null)
            {
                return;
            }

            if (!PleaseWaitWindow.Dispatcher.CheckAccess())
            {
                PleaseWaitWindow.Dispatcher.Invoke(new UpdateStatusTextDelegate(UpdateStatusText), new object[] { text, windowWidth });
                return;
            }

            PleaseWaitWindow.Text     = _currentStatusText;
            PleaseWaitWindow.MinWidth = double.IsNaN(_currentWindowWidth) ? 0d : _currentWindowWidth;
            PleaseWaitWindow.UpdateLayout();
        }
Exemple #3
0
        /// <summary>
        /// Shows the window delayed by using the <see cref="MinimumDurationBeforeShow"/>.
        /// </summary>
        /// <param name="percentage">
        /// The percentage. If <c>-1</c>, the window is assumed to be indeterminate.
        /// </param>
        private void ShowWindow(int percentage)
        {
            bool isIndeterminate = (percentage == -1);

            var pleaseWaitWindow = PleaseWaitWindow;

            if (pleaseWaitWindow != null)
            {
                pleaseWaitWindow.IsIndeterminate = isIndeterminate;
                pleaseWaitWindow.Percentage      = percentage;
                return;
            }

            pleaseWaitWindow = new PleaseWaitWindow();
            var activeWindow = Application.Current.GetActiveWindow();

            // When the application has no a WPF window then the active window could be the pleaseWaitWindow, so
            if (!pleaseWaitWindow.Equals(activeWindow))
            {
                pleaseWaitWindow.Owner = activeWindow;
            }

            pleaseWaitWindow.IsIndeterminate = isIndeterminate;
            pleaseWaitWindow.Percentage      = percentage;
            pleaseWaitWindow.Text            = _currentStatusText;
            pleaseWaitWindow.MinWidth        = double.IsNaN(_currentWindowWidth) ? 0d : _currentWindowWidth;

            Log.Debug("Showing please wait window");

            pleaseWaitWindow.Show();

            // Skip the turn dark wait loop if there are nothing to turn dark.
            if (pleaseWaitWindow.Owner != null)
            {
                // Yes, check for PleaseWaitWindow (property). Sometimes the show immediately hides
                while (!pleaseWaitWindow.IsOwnerDimmed && PleaseWaitWindow != null)
                {
                    // It's a bad practice to use this "equivalent" of DoEvents in WPF, but I don't see another choice
                    // to wait until the animation of the ShowWindow has finished without blocking the UI
                    pleaseWaitWindow.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate { });
                    pleaseWaitWindow.UpdateLayout();
                }
            }

            // The property is set when the window is displayed
            PleaseWaitWindow = pleaseWaitWindow;

            lock (_visibleStopwatchLock)
            {
                if (_visibleStopwatch == null)
                {
                    _visibleStopwatch = new Stopwatch();
                    _visibleStopwatch.Start();
                }
                else
                {
                    _visibleStopwatch.Reset();
                    _visibleStopwatch.Start();
                }
            }
        }
        /// <summary>
        /// Shows the window delayed by using the <see cref="MinimumDurationBeforeShow"/>.
        /// </summary>
        /// <param name="percentage">
        /// The percentage. If <c>-1</c>, the window is assumed to be indeterminate.
        /// </param>
        private void ShowWindow(int percentage)
        {
            bool isIndeterminate = (percentage == -1);

            var pleaseWaitWindow = PleaseWaitWindow;
            if (pleaseWaitWindow != null)
            {
                pleaseWaitWindow.IsIndeterminate = isIndeterminate;
                pleaseWaitWindow.Percentage = percentage;
                return;
            }

            pleaseWaitWindow = new PleaseWaitWindow();
            var activeWindow = Application.Current.GetActiveWindow();

            // When the application has no a WPF window then the active window could be the pleaseWaitWindow, so
            if (!pleaseWaitWindow.Equals(activeWindow))
            {
                pleaseWaitWindow.Owner = activeWindow;
            }

            pleaseWaitWindow.IsIndeterminate = isIndeterminate;
            pleaseWaitWindow.Percentage = percentage;
            pleaseWaitWindow.Text = _currentStatusText;
            pleaseWaitWindow.MinWidth = double.IsNaN(_currentWindowWidth) ? 0d : _currentWindowWidth;

            Log.Debug("Showing please wait window");

            pleaseWaitWindow.Show();

            // Skip the turn dark wait loop if there are nothing to turn dark. 
            if (pleaseWaitWindow.Owner != null)
            {
                // Yes, check for PleaseWaitWindow (property). Sometimes the show immediately hides
                while (!pleaseWaitWindow.IsOwnerDimmed && PleaseWaitWindow != null)
                {
                    // It's a bad practice to use this "equivalent" of DoEvents in WPF, but I don't see another choice
                    // to wait until the animation of the ShowWindow has finished without blocking the UI
                    pleaseWaitWindow.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart)delegate { });
                    pleaseWaitWindow.UpdateLayout();
                }
            }

            // The property is set when the window is displayed
            PleaseWaitWindow = pleaseWaitWindow;

            lock (_visibleStopwatchLock)
            {
                if (_visibleStopwatch == null)
                {
                    _visibleStopwatch = new Stopwatch();
                    _visibleStopwatch.Start();
                }
                else
                {
                    _visibleStopwatch.Reset();
                    _visibleStopwatch.Start();
                }
            }
        }