i developing app holds multiple files download, getting single file @ time.
code implemented on button click download file below:
private async void buttondownload_click_1(object sender, routedeventargs e) { string uri = "download url****************************"; storagefolder folder = applicationdata.current.localfolder; if (folder != null) { storagefile file = await folder.createfileasync(++fileno + "stvideo.mp4", creationcollisionoption.generateuniquename); downloadoperation = backgrounddownloader.createdownload(new uri(uri), file); progress<downloadoperation> progress = new progress<downloadoperation>(progresschanged); cancellationtoken = new cancellationtokensource(); try { textblockstatus.text = "initializing..."; await downloadoperation.startasync().astask(cancellationtoken.token, progress); } catch (taskcanceledexception) { textblockstatus.text = "download canceled."; downloadoperation.resultfile.deleteasync().astask().wait(); buttondownload.isenabled = true; downloadoperation = null; } } } and progress changed event following:
private void progresschanged(downloadoperation downloadoperation) { int progress = (int)(100 * ((double)downloadoperation.progress.bytesreceived / (double)downloadoperation.progress.totalbytestoreceive)); textblockprogress.text = string.format("{0} of {1} kb. downloaded - %{2} complete.", downloadoperation.progress.bytesreceived / 1024, downloadoperation.progress.totalbytestoreceive / 1024, progress); progressbardownload.value = progress; switch (downloadoperation.progress.status) { case backgroundtransferstatus.running: { textblockstatus.text = "downloading..."; break; } case backgroundtransferstatus.completed: { textblockstatus.text = "download complete."; downloadoperation = null; break; } case backgroundtransferstatus.pausedbyapplication: { textblockstatus.text = "download paused."; break; } case backgroundtransferstatus.pausedcostednetwork: { textblockstatus.text = "download paused because of metered connection."; break; } case backgroundtransferstatus.pausednonetwork: { textblockstatus.text = "no network detected. please check internet connection."; break; } case backgroundtransferstatus.error: { textblockstatus.text = "an error occured while downloading."; break; } } } but unable come solution download multiple files.
please elaborate me how rid out problem.
thanks
if clicked twice or more - create multiple downloads 1 progress handler. when created download operation item system generates unique id - guid. can determine item downloads in progresschanged
as know:
maximum download operations in same moment - 5
maximum download operations in queue - 500
update:
i created simple sample background downloading. can download sample onedrive
Comments
Post a Comment