Reputation: 4269
I have two tasks which download an mp3 from web address inside local storage and returns 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;
}
Now I need to show an indeterminate progressbar in UI while downloading starts till it ends But dont know how to find the task completed?
On my NavigatedTo function I have set it as async and am calling await downloadFile();
Now inside my downloadFile()
public async Task<TimeSpan> downloadFiles()
{
//ProgressShow
var temp= await filedownload_Ignition_Outside();
//if (filedownload_Ignition_Outside().IsCompleted)
//{
// //progressStop
//}
return temp;
}
But its not executing the stop statement as it waits asynchronously how can I get the event where both task gets finished?
Can I call both tasks inside my downloadFiles() method and still able to get an event for both task completion.
Upvotes: 3
Views: 413
Reputation: 9309
Try something similar to the code given below in your OnNavigatedTo
event.
ShowProgress=true;
downloadFiles().ContinueWith((sender) =>
{
this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
ShowProgress=false;
);
});
You need to run the ShowProgress=False;
in UI thread
Upvotes: 1