Пример #1
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();
                }
            }
        }
Пример #2
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();
                }
            }
        }