private async Task LoadingDelayAsync(LoadingAsyncConfig config, int loadingCount) { if (loadingCount % 2 == 0) { Timer timer = null; await Task.WhenAll(Task.Delay(TimeSpan.FromSeconds(5)), Task.Run(() => { timer = new Timer((_) => { if (config.Progress.HasValue) { config.Progress++; } else { config.Progress = 0; } }, null, 0, 40); })); timer.Dispose(); } else { await Task.Delay(TimeSpan.FromSeconds(5)); } }
public async void Loading() { var config = new LoadingAsyncConfig { Title = "Loading Async", Message = "Hello World!" }; await MessagingService.Instance.LoadingAsync(config, () => LoadingDelayAsync(config, _loadingCount++)); }
/// <summary> /// Display a loading dialog asynchronously. /// </summary> /// <param name="config">The dialog configuration.</param> /// <param name="task">A function to retrieve the task to execute.</param> public virtual async Task LoadingAsync(LoadingAsyncConfig config, Func <Task> task, CancellationToken cancellationToken = default) { // If available, call the delegate to see if presenting this dialog is allowed. if (MessagingServiceCore.Delegate != null && !MessagingServiceCore.Delegate.OnLoadingRequested(config)) { return; } var dialog = PresentLoading(config); // Register the disposable of the dialog with the cancellation token, then return the task. using (cancellationToken.Register(() => dialog.Dispose())) { try { await task.Invoke().ConfigureAwait(false); } finally { dialog.Dispose(); } } }
/// <summary> /// Display a loading dialog asynchronously. /// </summary> /// <param name="config">The dialog configuration.</param> /// <param name="task">A function to retrieve the task to execute.</param> public virtual async Task <T> LoadingAsync <T>(LoadingAsyncConfig config, Func <Task <T> > task, CancellationToken cancellationToken = default) { // If available, call the delegate to see if presenting this dialog is allowed. if (MessagingServiceCore.Delegate != null && !MessagingServiceCore.Delegate.OnLoadingRequested(config)) { return(default);