我有两个任务,从本地存储中的网址下载 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/