/// <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;
});
}