如何在Xamarin Android中使用Threadpool下载2个文件?
我使用下面的代码下载PDF文件在按钮点击。如何在threadpool中下载2个文件如何在Xamarin Android中使用Threadpool下载2个文件?,android,multithreading,file,xamarin,threadpool,Android,Multithreading,File,Xamarin,Threadpool,我使用下面的代码下载PDF文件在按钮点击。如何在threadpool中下载2个文件 private async Task DownloadPDF(string urls, string shortName, object downloadProgressCalculator) { m_downLoadProgress = downloadProgressCalculator as DownloadProgressCalculator;
private async Task DownloadPDF(string urls, string shortName, object downloadProgressCalculator)
{
m_downLoadProgress = downloadProgressCalculator as DownloadProgressCalculator;
var pathFile = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);
var absolutePath = pathFile.AbsolutePath;
var m_documentMobiNames = shortName + ".pdf";
var mobileFileNames = Path.Combine(absolutePath, m_documentMobiNames);
ThreadPool.QueueUserWorkItem((object state) =>
{
try
{
if (File.Exists(mobileFileNames))
{
File.Delete(mobileFileNames);
}
if (!File.Exists(mobileFileNames))
{
m_webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
m_webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_DownloadFileCompleted);
m_webClient.DownloadFileAsync(new Uri(urls), mobileFileNames);
}
}
catch (Exception ex)
{
}
});
}
请提出你的想法
感谢如何使用m_webClient下载2个文件。DownloadFileAsync(新Uri(URL)、mobileFileNames);您想同时下载两个文件还是按顺序下载?两个文件的文件名相同?我看到了你的答案,这个答案不能解决你的问题吗?如何使用m_webClient.DownloadFileAsync(新Uri(URL),mobileFileNames)下载2个文件;您想同时下载两个文件还是按顺序下载?两个文件的文件名相同?我看到了你的答案,这个答案不能解决你的问题吗?