iOSHelpers.BackgroundDownload.DownloadFileAsync C# (CSharp) Method

DownloadFileAsync() public method

public DownloadFileAsync ( Uri url, string destination ) : Task
url System.Uri
destination string
return Task
		public async Task<nuint> DownloadFileAsync (Uri url, string destination)
		{
			this.Url = url.AbsoluteUri;
			if (downloadTask != null)
				return downloadTask.TaskIdentifier;
			if (session == null) {
				Initalize ();
			}
			Destination = destination;

			SessionId = session.Configuration.Identifier;
			if (!BackgroundDownloadManager.Tasks.TryGetValue (url.AbsoluteUri, out Tcs)) {
				Tcs = new TaskCompletionSource<bool> ();
				BackgroundDownloadManager.Tasks.Add (url.AbsoluteUri, Tcs);
				using (var request = new NSUrlRequest (new NSUrl (url.AbsoluteUri))) {
					downloadTask = session.CreateDownloadTask (request);
					downloadTask.Resume ();
				}
			}

			BackgroundDownloadManager.AddController (this.Url, this);

			await Tcs.Task;

			return downloadTask.TaskIdentifier; 
		}

Usage Example

        public static BackgroundDownload Download(Uri url, string destination)
        {
            var download = new BackgroundDownload();

            //We dont want to await this. Just get it started
                        #pragma warning disable 4014
            download.DownloadFileAsync(url, destination);
                        #pragma warning restore 4014
            return(download);
        }
All Usage Examples Of iOSHelpers.BackgroundDownload::DownloadFileAsync