示例#1
0
    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));
        }
    }
示例#2
0
    public async void Loading()
    {
        var config = new LoadingAsyncConfig {
            Title = "Loading Async", Message = "Hello World!"
        };

        await MessagingService.Instance.LoadingAsync(config, () => LoadingDelayAsync(config, _loadingCount++));
    }
示例#3
0
    /// <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();
            }
        }
    }
示例#4
0
 /// <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);