How To View The Downloaded File When Another Download Is In Progress Using Xamarin Android
I am implementing a mobile app using Xamarin android. I have implemented a code to download both.PDF and .Mobi file in a button click. I have used the below code. ... awa
Solution 1:
Since you're not showing any UI stuff i guess you have that covered to i will omit that.
Instead of writing: await Task.WhenAll(DownloadPDF(), DownloadMobi());
do the following
await DownloadPDF();
// update button to display "View PDF"// add button click listener (optional if it's already registered)// open file in PDF reader
await DownloadMobi();
Solution 2:
Use ContinueWith Method of Task
var task = DownloadPDF();
task.ContinueWith((pdfDownloadTask)=>DownloadMobi());
This will continue execution of next task after pdf download task is complete
Solution 3:
private stringBuilder urlStr = null;
publicvoidDownloadFiles()
{
List<string> url = new List<string>();
urlStr = new StringBuilder();
url.add("http://files/file.pdf");
url.add("http://files/file.mobi");
var tasks = new List<Task>();
foreach(var tempUrl in url)
{
tasks.add(DownloadMobiAndPdf(tempUrl);
}
Task.WhenAll(tasks));
}
privateasync Task DownloadMobiAndPdf(string url)
{
using(var client = new WebClient())
{
urlStr.Append(url);
await client.DonwloadFileTaskAsync(url);
client.DownloadFileCompleted+=Client_DownloadFileCompleted;
}
}
privatestaticvoidClient_DownloadFileCompleted(object
sender,System.ComponentModel.AsyncCompletedEventArgs e)
{
if(e.Error == null)
{
//No errorif(urlStr.Contains("pdf")
{
//Enable button
}
}
}
Post a Comment for "How To View The Downloaded File When Another Download Is In Progress Using Xamarin Android"