internal void Show(DialogShowArguments args)
        {
            try
            {
                if (_disposed)
                {
                    throw new ObjectDisposedException(nameof(ShowDialogTask));
                }
                if (_dataSource == null)
                {
                    return;
                }

                _isDialogAcquired               = true;
                _dataSource.Caption             = string.IsNullOrEmpty(args.Caption) ? _hostAppName : args.Caption;
                _dataSource.WaitMessage         = string.IsNullOrEmpty(args.WaitMessage) ? _hostAppName : args.WaitMessage;
                _dataSource.ProgressMessage     = args.ProgressMessage;
                _dataSource.IsCancellable       = args.IsCancellable;
                _dataSource.IsProgressVisible   = args.IsProgressVisible;
                _dataSource.ShowMarqueeProgress = args.ShowMarqueeProgress;

                if (_dataSource.IsProgressVisible && !_dataSource.ShowMarqueeProgress)
                {
                    _dataSource.CurrentStep = args.CurrentStepCount;
                    _dataSource.TotalSteps  = args.TotalStepCount;
                }

                _application?.Dispatcher?.Invoke(() => ShowDialogTask(args));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemple #2
0
 private void StartWaitDialogHelper(string caption, string waitMessage, string progressText,
                                    int delayToShowDialog, bool isCancellable, bool isProgressVisible,
                                    int currentStepCount = 0, int totalStepCount = -1, IWaitDialogCallback callback = null)
 {
     if (!ThreadHelper.CheckAccess())
     {
         ThreadHelper.Generic.Invoke(() =>
         {
             StartWaitDialogHelper(caption, waitMessage, progressText, delayToShowDialog,
                                   isCancellable, isProgressVisible, currentStepCount, totalStepCount, callback);
         });
     }
     else
     {
         ThreadHelper.ThrowIfNotOnUIThread(nameof(StartWaitDialogHelper));
         lock (_syncObject)
         {
             if (_instance == null)
             {
                 _instance = WaitDialog.AcquireInstance();
             }
             if (_instance == null)
             {
                 _isDialogStarted = true;
             }
             else
             {
                 _isUiSuppressed = IsUiSuppressed();
                 if (!_isUiSuppressed)
                 {
                     try
                     {
                         var args = new DialogShowArguments(caption, waitMessage, progressText, isCancellable,
                                                            isProgressVisible, currentStepCount, totalStepCount)
                         {
                             AppMainWindowHandle = GetPrimaryWindowHandle()
                         };
                         _instance.Show(TimeSpan.FromSeconds(delayToShowDialog), args, callback);
                         _isDialogStarted = true;
                     }
                     catch
                     {
                         WaitDialog.ReleaseInstance(_instance);
                         _instance = null;
                         throw;
                     }
                 }
                 else
                 {
                     _isDialogStarted = true;
                 }
             }
         }
     }
 }
        private async Task ShowInternalAsync(TimeSpan delayToShowDialog, DialogShowArguments showArguments)
        {
            var localInstanceId = _currentInstanceId;

            _dialogArguments = showArguments;
            await Task.Delay(delayToShowDialog).ConfigureAwait(false);

            if (localInstanceId != _currentInstanceId || !_isInstanceAcquired)
            {
                return;
            }
            _isDialogActive = true;
            _provider.Show(showArguments);
        }
        public void Show(TimeSpan delayToShowDialog, DialogShowArguments showArguments, IWaitDialogCallback callback = null)
        {
            if (_disposed)
            {
                return;
            }
            if (showArguments == null)
            {
                throw new ArgumentNullException(nameof(showArguments));
            }
            ThreadHelper.ThrowIfNotOnUIThread(nameof(Show));
            EnsureInitialized();

            var activeWindow = NativeMethods.NativeMethods.GetActiveWindow();
            var windowText   = NativeMethods.NativeMethods.GetWindowText(GetRootOwnerWindow(activeWindow));

            showArguments.SetActiveWindowArgs(windowText, activeWindow);
            IsCancelled           = false;
            _cancellationCallback = callback;
            ShowInternalAsync(delayToShowDialog, showArguments).Forget();
        }
 private void ShowDialogTask(DialogShowArguments args)
 {
     _window.TryShowDialog(args.AppMainWindowHandle, args.ActiveWindowHandle, args.RootWindowCaption);
 }