AsyncImageAndroid.DownloadManager.DownloadAsync C# (CSharp) Method

DownloadAsync() public method

public DownloadAsync ( string downloadUrl, string fileName ) : Task
downloadUrl string
fileName string
return Task
		public async Task<string> DownloadAsync(string downloadUrl, string fileName)
		{
			webClient = new WebClient ();
			webClient.DownloadProgressChanged += HandleDownloadProgressChanged;

			var url = new Uri (downloadUrl);
 			//TODO uncomment the line below to fix memory leak
			//byte[] bytes = await webClient.DownloadDataTaskAsync(url);

			//TODO comment out the line below to fix memory leak
			bytes = await webClient.DownloadDataTaskAsync(url);

			string localPath = FetchStorePath (fileName);
			await StoreData (bytes, localPath);

			return localPath;
		}

Usage Example

Ejemplo n.º 1
0
        async void DownloadAsync(object sender, EventArgs args)
        {
            clickButton.Click += manager.EventHandler;

            SetDownloading();

            string filePath = string.Empty;

            try {
                filePath = await manager.DownloadAsync(downloadUrl, "downloaded.png");
            } catch (TaskCanceledException) {
                Console.WriteLine("Task Canceled!");
                SetReadyToDownload();
                return;
            } catch (Exception exc) {
                Console.WriteLine(exc);
                SetReadyToDownload();
                return;
            }

            infoLabel.Text = "Resizing Image...";

            var bitmap = await FetchBitmap(filePath);

            imageview.SetImageBitmap(bitmap);
            SetReadyToDownload();

            // Solution is here
            clickButton.Click -= manager.EventHandler;
        }