c# - Windows Phone 8.1 在异步/等待任务完成之前显示进度 View

标签 c# asynchronous windows-phone-8.1 win-universal-app

我有两个任务,从本地存储中的网址下载 mp3 并返回 timeSpan。

 public async Task<TimeSpan> filedownload_Ignition_Outside()
            {
                Uri sourceIgnition_Outside = new Uri(TemporaryAddress.download_playCarSound+"Ignition_Outside");
//download and store file

                return duration_Ignition_Outside;
            }






public async Task<TimeSpan> filedownload_Idle_Outside()
    {
        Uri sourceIdle_Outside = new Uri(TemporaryAddress.download_playCarSound +"Idle_Outside");
        StorageFile destinationFileIdle_Outside;
       //download and store file

        return duration_Idle_Outside;

    }

现在我需要在下载开始到结束时在 UI 中显示一个不确定的进度条但是不知道如何找到已完成的任务?

在我的 NavigatedTo 函数中,我已将其设置为异步并正在调用 等待下载文件();

现在在我的 downloadFile()

 public async Task<TimeSpan> downloadFiles()
            {
                //ProgressShow



              var temp= await filedownload_Ignition_Outside();



                //if (filedownload_Ignition_Outside().IsCompleted)
                //{
                //    //progressStop
                //}

return temp;

    }

但是它不执行停止语句,因为它是异步等待的,我怎样才能得到两个任务都完成的事件?
我可以在我的 downloadFiles() 方法中调用两个任务并且仍然能够获得两个任务完成的事件。

最佳答案

在您的 OnNavigatedTo 事件中尝试类似于下面给出的代码。

          ShowProgress=true;
           downloadFiles().ContinueWith((sender) =>
            {
                this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                   ShowProgress=false;
                );
            });

您需要在 UI 线程中运行 ShowProgress=False;

关于c# - Windows Phone 8.1 在异步/等待任务完成之前显示进度 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30636839/

相关文章:

c# - 什么是 ObjectFactory.Inject 在 StructureMap 3.0 中的等价物

c# - 使用 DotNetOpenAuth 访问 Yelp 的 OAuth 1.0a API

c# - 每 3 秒重新加载 GridView,而不中断 UI

angularjs - 如何在 Angular 循环中使用异步调用?

c# - 输入对话框消息框(Windows Phone 8.1 通用)

c# - 使用 Google 代码中的代码

c# - 在 C# 中,为什么要使用表达式树以及何时需要使用它们?

c# - 如何将Dispatcher或Task的值传递给外部?

networking - 如何在Windows Phone模拟器上启用Wi-Fi并搜索网络

c# - 无法设置 Content-Type header