MahApps.Metro.Controls.Dialogs.ProgressDialogController.SetProgress C# (CSharp) Method

SetProgress() public method

Sets the dialog's progress bar value and sets IsIndeterminate to false.
public SetProgress ( double value ) : void
value double The percentage to set as the value.
return void
        public void SetProgress(double value)
        {
            Action action = () =>
                {
                    if (value < this.WrappedDialog.Minimum || value > this.WrappedDialog.Maximum)
                    {
                        throw new ArgumentOutOfRangeException(nameof(value));
                    }
                    this.WrappedDialog.ProgressValue = value;
                };
            this.WrappedDialog.Invoke(action);
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        ///     Runs CanEnable asynchronously multiple times until successful, cancelled or max tries reached
        /// </summary>
        /// <param name="dialog"></param>
        /// <returns></returns>
        public Task<bool> CanEnableAsync(ProgressDialogController dialog)
        {
            return Task.Run(() =>
            {
                for (var tries = 1; tries <= 10; tries++)
                {
                    // Dialog interaction
                    if (dialog != null)
                    {
                        // Stop if cancelled by user
                        if (dialog.IsCanceled)
                        {
                            dialog.SetIndeterminate();
                            return false;
                        }
                        // Updated progress to indicate how much tries are left
                        dialog.SetProgress(0.1*tries);
                    }

                    if (CanEnable())
                    {
                        dialog?.SetIndeterminate();
                        return true;
                    }
                    Thread.Sleep(2000);
                }
                dialog?.SetIndeterminate();
                return false;
            });
        }
All Usage Examples Of MahApps.Metro.Controls.Dialogs.ProgressDialogController::SetProgress